Pagini recente » Cod sursa (job #793157) | Cod sursa (job #2188313) | Cod sursa (job #2614927) | Cod sursa (job #553274) | Cod sursa (job #1064499)
#include<cstdio>
#include<deque>
#include<climits>
#include<utility>
#include<string>
#include<cstring>
using namespace std ;
int N, posm, MAX = INT_MIN, K, lg ;
deque <pair <int, int> > dq ;
//string S ;
char S[5000000];
int next(char *S, int &pos) {
int x = 0, s = 0;
while (pos < lg && !isdigit(S[pos])) { if(S[pos] == '-') s = 1; ++pos ;}
while (pos <lg && isdigit(S[pos])) {
x = x * 10 + (S[pos] - '0') ;
++pos ;
}
if (s) x *= -1 ;
//printf("%d\n", x) ;
return x;
}
int main() {
int i, x, pos = 0 ;
freopen("secventa.in", "r", stdin) ;
freopen("secventa.out", "w", stdout) ;
gets(S) ;
lg = strlen(S) ;
N = next(S, pos) ;
K = next(S, pos) ;
gets(S) ;
lg = strlen(S) ;
pos = 0 ;
x = next(S, pos) ;
dq.push_back(make_pair(x, 1)) ;
for (i = 2; i <= K; ++i) {
x = next(S, pos) ;
while(!dq.empty() && x <= dq.back().first) {
dq.pop_back() ;
}
dq.push_back(make_pair(x, i)) ;
}
MAX = dq.front().first ;
posm = K ;
for (i = K + 1; i <= N; ++i) {
if (dq.front().second == i - K) {
dq.pop_front() ;
}
x = next(S, pos) ;
while(!dq.empty() && x <= dq.back().first) {
dq.pop_back() ;
}
dq.push_back(make_pair(x, i)) ;
if (dq.front().first > MAX) {
MAX = dq.front().first ;
posm = i ;
}
}
printf("%d %d %d", posm - K + 1, posm, MAX) ;
return 0 ;
}