Cod sursa(job #717417)
| Utilizator | Data | 19 martie 2012 21:56:53 | |
|---|---|---|---|
| Problema | Secventa | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
#include<fstream>
#include<deque>
using namespace std;
int main()
{ifstream f("secventa.in");
ofstream h("secventa.out");
int n,k,a[500000],i,y,max=-30001;
deque<int> p;
f>>n>>k;
for(i=1;i<=n;i++)
f>>a[i];
for(i=1;i<=n;i++)
{while(!p.empty()&&a[i]<a[p.back()])
p.pop_back();
p.push_back(i);
if(p.front()==i-k)
p.pop_front();
if(i>=k)
if(a[p.front()]>max)
{max=a[p.front()];
y=i;}}
h<<y-k+1<<" "<<y<<" "<<max;
return 0;}