Pagini recente » Cod sursa (job #115601) | Cod sursa (job #799685) | Cod sursa (job #1657511) | Cod sursa (job #1429605) | Cod sursa (job #2122708)
#include<fstream>
#include<map>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int N,K,V[500003],Max=-100000000,Poz;
map <int, int> Map;
map <int, int>::iterator It;
int main()
{
fin>>N>>K;
for(int i=1;i<=N;i++)
fin>>V[i];
for(int i=1;i<=K;i++)
Map[V[i]]++;
It=Map.begin();
Max=It->first;
Poz=1;
for(int i=K+1;i<=N;i++)
{
if(Map[V[i-K]]==1)
Map.erase(V[i-K]);
else
Map[V[i-K]]--;
Map[V[i]]++;
It=Map.begin();
if(It->first>Max)
{
Poz=i-K+1;
Max=It->first;
}
}
fout<<Poz<<" "<<Poz+K-1<<" "<<Max<<'\n';
}