Pagini recente »
Cod sursă (job #543023)
|
Cod sursă (job #94886)
|
Istoria paginii runda/vaslui_cls78_02.02/clasament
|
Borderou de evaluare (job #642783)
|
Cod sursă (job #94888)
Cod sursă (job
#94888)
#include <cstdio>
#include <algorithm>
#define N_MAX 5000000
using namespace std;
struct floare{
int h, z;
};
bool mod(floare a,floare b){
return a.h < b.h;
}
floare v[5000001];
int main(){
FILE *fin, *fout;
fin = fopen("lalele.in","r");
fout = fopen("lalele.out","w");
int n, x, y, top, zi, i;
// Citim
fscanf(fin, "%d", &n);
while (i < n) {
fscanf(fin, "%d%d", &x, &y);
i += x;
if (y != 0) {
for (int j = 1; j <= x; ++j) {
v[++top].h = y;
v[top].z = ++zi;
}
}
else {
for (int j = 1; j <= x; ++j){
++zi;
for (int l = 1; l <= top; ++l){
v[l].h += zi-v[l].z;
v[l].z = zi;
}
nth_element(v + 1, v + top / 2 + 1, v + top + 1, mod);
top = top / 2;
// Afisam
fprintf(fout, "%d\n", v[top+1]);
}
}
}
return 0;
}