Cod sursa(job #929646)

Utilizator rudarelLup Ionut rudarel Data 27 martie 2013 10:14:54
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <stdio.h>
#define MAX 500000
#define IN "secventa.in"
#define OUT "secventa.out"

using namespace std;

long int n, k, a[MAX];

int main()
{
    long int i = 0, max = 0, poz = 1;
    FILE *fin = fopen(IN, "r");
    ofstream fout(OUT);
    fscanf(fin, "%ld %ld", &n, &k);
    for ( i = 1; i <= k; i++ )
    {
        fscanf(fin, "%ld", &a[i]);
        if ( max < a[i] )
        {
            max = a[i];
            poz = i;
        }
    }
    for ( i = k + 1; i <= n; i++ )
    {
        fscanf(fin, "%ld", &a[i]);
        if ( max < a[i] && n - k >= i - 1 )
        {
            max = a[i];
            poz = i;
        }
    }
    fout << poz << " " << poz + k - 1 << " " << max << "\n";
    fclose(fin);
    fout.close();
    return 0;
}