Pagini recente »
Borderou de evaluare (job #103417)
|
Cod sursă (job #362875)
|
Cod sursă (job #691964)
|
Istoria paginii runda/concursul/clasament
|
Cod sursă (job #563596)
Cod sursă (job
#563596)
#include <fstream>
#include <algorithm>
#define NMAX 5000005
using namespace std;
ifstream f("lalele.in");
ofstream g("lalele.out");
int n, days, x, total_days;
int day[NMAX], height[NMAX];
int main()
{
f >> n;
n = 0;
while(f >> days >> x)
{
if(x != 0)
{
for(int i = 1; i <= days; i++)
{
height[++n] = x;
day[n] = ++total_days;
}
}
else
{
for(int i = 1; i <= n; i++)
{
height[i] = height[i] + total_days - day[i];
day[i] = total_days;
}
for(int i = 1; i <= days; i++)
{
total_days++;
nth_element(height + 1, height + n / 2 + 1, height + n + 1);
g << height[n / 2 + 1] + total_days - day[n / 2 + 1] << "\n";
n = n / 2;
}
}
}
return 0;
}