Nu aveti permisiuni pentru a descarca fisierul grader_test4.ok
Cod sursa(job #1849969)
Utilizator | Data | 17 ianuarie 2017 23:50:37 | |
---|---|---|---|
Problema | Lupul Urias si Rau | Scor | 48 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.85 kb |
#include <bits/stdc++.h>
using namespace std;
struct str{
int l,t;
}a[100005];
int tp,tc;
int cmp(str,str);
priority_queue <int> q;
int n,dmax,l,s;
int main(){
freopen("lupu.in","r",stdin);
freopen("lupu.out","w",stdout);
cin>>n>>dmax>>l;
for (int i=1;i<=n;i++){
int d;
cin>>d>>a[i].l;
if (d>dmax){
a[i].t=0;
}
else {
a[i].t=(dmax-d)/l+1;
}
}
sort(a+1,a+n+1,cmp);
tp=0;
int i=1;
while (i<=n){
tp=a[i-1].t;
tc=a[i].t;
while (tp>tc&&!q.empty()){
s+=q.top();
q.pop();
tp--;
}
while (a[i].t==tc&&i<=n){
q.push(a[i].l);
i++;
}
}
cout<<s+q.top();
}
int cmp(str a,str b){
return a.t>b.t;
}