Pagini recente » Cod sursa (job #257264) | Cod sursa (job #283231) | Cod sursa (job #602400) | Cod sursa (job #2957593) | Cod sursa (job #1963171)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
int n, i, j, mx=-30005, a, b, x, k, nr;
string s;
deque <int> dq, pq;
int main()
{
ifstream fin("secventa.in");
ofstream fout("secventa.out");
fin >> n >> k;
getline(fin, s);
getline(fin, s);
for (i = 0; i < s.size(); i++)
{
if (s[i] == ' ') continue;
if (s[i] == '-')
{
x = 0;
i++;
while (s[i] != ' ' && i < s.size())
{
x = x * 10 - (s[i]-'0');
i++;
}
}
else if (s[i] != ' ')
{
x = 0;
while (s[i] != ' ' && i < s.size())
{
x = x * 10 + (s[i]-'0');
i++;
}
}
nr++;
if (!dq.empty() && pq.front() <= nr-k)
{
pq.pop_front();
dq.pop_front();
}
while (!dq.empty() && dq.back() >= x)
{
pq.pop_back();
dq.pop_back();
}
pq.push_back(nr);
dq.push_back(x);
if (nr >= k && dq.front() > mx)
{
b = pq.back(); a = b-k+1;
mx = dq.front();
}
}
fout << a << " " << b << " " << mx << "\n";
}