Pagini recente »
Atașamentele paginii Clasament mongol_11_12
|
joi
|
vaslui_cls10_02.03
|
Monitorul de evaluare
|
Cod sursă (job #134413)
Cod sursă (job
#134413)
#include <fstream>
#include <cstdio>
#include <vector>
using namespace std;
ofstream fout("lalele.out");
int day,n,d,x;
struct HEAP{int z,h;};
HEAP aux,vmin;
vector<HEAP> heap;
bool H(HEAP h1,HEAP h2)
{
return (day-h1.z)+h1.h>(day-h2.z)+h2.h;
}
void down()
{
int tata,fiu;
tata=1; aux=heap[1];
while(tata*2<heap.size())
{
fiu=tata*2;
if(fiu+1<heap.size())
if(H(heap[fiu+1],heap[fiu])==true)
fiu++;
if(H(heap[fiu],aux)==true)
heap[tata]=heap[fiu],tata=fiu;
else
break;
}
heap[tata]=aux;
}
int elimin(int d)
{
int jum;
while(d!=0)
{
d--; day++;
jum=(heap.size()-1)/2;
if((heap.size()-1)%2==1)
jum++;
for(int i=1;i<=jum;i++)
{
vmin=heap[1];
heap[1]=heap[heap.size()-1];
heap.pop_back();
down();
}
fout<<(vmin.h+(day-vmin.z))<<'\n';
}
}
void up()
{
int poz;
poz=heap.size()-1; aux=heap[heap.size()-1];
while(poz>1 && H(aux,heap[poz/2])==true)
{
heap[poz]=heap[poz/2];
poz/=2;
}
heap[poz]=aux;
}
void adaug(int d,int x)
{
aux.h=x;
while(d)
{
aux.z=++day;
heap.push_back(aux);
up();
d--;
}
}
int main()
{
freopen("lalele.in","r",stdin);
scanf("%d",&n);
heap.push_back(aux);
while(day<n)
{
scanf("%d%d",&d,&x);
if(x==0)
elimin(d);
else
adaug(d,x);
}
return 0;
}