Mai intai trebuie sa te autentifici.
Cod sursa(job #2774383)
Utilizator | Data | 11 septembrie 2021 15:04:55 | |
---|---|---|---|
Problema | Lupul Urias si Rau | Scor | 32 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.73 kb |
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
long long n,x,l,a,b,maxim,i;
pair<long long, long long> v[100010];
multiset<long long> s;
multiset<long long>::iterator it;
int main(){
fin>>n>>x>>l;
for(i=1;i<=n;i++){
fin>>a>>b;
if(x>=a){
v[i].X=(x-a)/l+1;
v[i].Y=b;
}
}
sort(v+1,v+n+1);
for(i=v[n].X;i>=1;i--){
while(n>=1&&v[n].X==i){
s.insert(v[n].Y);
n--;
}
if(!s.empty()){
it=s.end();
it--;
maxim+=*it;
s.erase(*it);
}
}
fout<<maxim;
return 0;
}