Pagini recente » Cod sursa (job #1431990) | Cod sursa (job #1704613) | Cod sursa (job #1431619) | Cod sursa (job #854692) | Cod sursa (job #2720025)
//ALEXANDRU MICLEA
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>
#include <assert.h>
#include <iostream>
using namespace std;
using ll = long long;
#define fast_cin() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//VARIABLES
deque <int> q;
int ans = 0;
int v[500005];
//FUNCTIONS
class InParser {
private:
FILE* fin;
char* buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int& n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
}
else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
//MAIN
int main() {
#ifdef INFOARENA
InParser("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);
#endif
int n, k; cin >> n >> k;
int x = 0, y = 0;
int ans = -500005;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) {
while (!q.empty() && v[q.back()] > v[i]) q.pop_back();
q.push_back(i);
while (!q.empty() && q.front() + k <= i) q.pop_front();
if (!(k > i) && ans < v[q.front()]) {
ans = v[q.front()];
x = i - k + 1;
y = i;
}
}
cout << x << ' ' << y << ' ' << ans;
return 0;
}