ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1126. Magnetic Storms

Oh, yeeee... : 2569031 14:54:48 19 апр 2009 Gerasim Petrov Velchev 1126 C++ Accepted 0.187 829 КБ
Posted by Gerasim Petrov Velchev 19 Apr 2009 14:57
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int izv[100001];
int main(){
int m;
cin>>m;
priority_queue<int>k;
vector<int>x;
int a,br=0;
while(1)
{
cin>>a;
if(a==-1)break;
x.push_back(a);
k.push(a);
br++;
if(br==m)cout<<k.top()<<endl;
else
if(br>m)
{
izv[x[0]]++;
x.erase(x.begin());
while(izv[k.top()]){izv[k.top()]--;k.pop();}
cout<<k.top()<<endl;
}
}

system("pause");
return 0;
}
Re: Oh, yeeee... : 2569031 14:54:48 19 апр 2009 Gerasim Petrov Velchev 1126 C++ Accepted 0.187 829 КБ
Posted by panhantao 5 Jun 2011 21:40
well,can you give some more details about your algorithm?
I can't quite understand your algorithm.....thx
Re: Oh, yeeee... : 2569031 14:54:48 19 апр 2009 Gerasim Petrov Velchev 1126 C++ Accepted 0.187 829 КБ
Posted by The Financier 10 Aug 2011 00:11
No necessary in such a ugly algorithm, simple multiset works fine and fast
upd. map also works, and is faster

Edited by author 10.08.2011 02:37