Mai intai trebuie sa te autentifici.
Cod sursa(job #2466489)
| Utilizator | Data | 2 octombrie 2019 13:04:31 | |
|---|---|---|---|
| Problema | Lupul Urias si Rau | Scor | 16 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.97 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct wow
{
long long x,cost;
}v[100005];
bool compare (wow a,wow b)
{
return a.x<b.x||(a.x==b.x&&a.cost<b.cost);
}
priority_queue <pair <long long ,long long > > h;
long long n,i,dr,nr,l,d,init,x;
long long sum;
int main()
{
f>>n>>l>>x;
for (i=1;i<=n;i++)
{
f>>v[i].x>>v[i].cost;
}
sort (v+1,v+n+1,compare);
dr=n;
nr=0;
init=l;
while (l>=0)
{
while (v[dr].x>l-x&&dr>=1)
{
h.push({v[dr].cost,v[dr].x});
dr--;
}
while (!h.empty()&&nr*x+h.top().second>init)
{
h.pop();
}
if (!h.empty())
{
sum=sum+h.top().first;
h.pop();
nr++;
}
if (dr==0&&h.empty())
{
break;
}
l=l-x;
}
g<<sum;
return 0;
}
