# Cod sursa(job #154500)

Utilizator Data 11 martie 2008 11:22:56 Secventa 20 cpp done Arhiva de probleme 1.29 kb
``````#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector< vi > vii;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> ii;
#define PB push_back
#define SZ(v) v.size()
#define ALL(v) (v).begin(), (v).end()
#define FORIT(i,c) for (typeof((c).end()) i=(c).begin(); i!=(c).end(); ++i)
#define FOR(i,n) for (int i = 0; i<(n); ++i)
#define FORE(i,n) for (int i = 0; i<=(n); ++i)
#define FORI(i,n1,n2) for (int i = n1; i<(n2); ++i)
#define FORIE(i,n1,n2) for (int i = n1; i<=(n2); ++i)
#define FORV(i,v) for (unsigned int i = 0; i<SZ(v); ++i)

#define INF 0x3f3f3f3f
#define EPS 1e-9

#define NMAX 500001

set<int> S;
int N,K;
int A[NMAX];

int main()
{
freopen("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);

cin >> N >> K;

FOR(i,N)
cin >> A[i];

FOR(i,K)
{
S.insert(A[i]);
}

int best = *S.begin();
int bestpos = 1;

FOR(i, N-K)
{
S.erase(A[i]);
S.insert(A[i+K]);
int y = *S.begin();
if (y > best)
{
best = y;
bestpos = i + 2;
}
}

printf("%d %d %d\n", bestpos, bestpos+K-1, best);

return 0;
}
``````