Cod sursa(job #2361658)

Utilizator greelioGreenio Greely greelio Data 2 martie 2019 17:43:37
Problema Lupul Urias si Rau Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<bits/stdc++.h>
#define pii pair<long long,int>
#define x first
#define y second
#define ll long long
using namespace std;

const ll inf=1e9;
pair<int,int> a[100010];
set<pii>S;
int n,x,l;
rs;

int main() {
    freopen ("lupu.in", "r", stdin);
    freopen ("lupu.out", "w", stdout);
    scanf("%d %d %d", &n, &x, &l);
    for (int i=1; i<=n; ++i) {
        int x,y; scanf("%d %d", &a[i].y, &a[i].x);
        S.insert({0,i});
    }
    sort(a+1,a+1+n, greater<pair<int,int>>());
    for (int i=1; i<=n; ++i) {
        pii t=a[i];
        ll r=(x-t.y)/l+1;
        if (r<=0) continue;
        auto it=S.upper_bound({0,r});
        if (it==S.begin()) continue;
        else --it;
        if (it->x==inf) continue;
        ll y=it->y;
        rs+=t.x;
        S.erase(it);
    }
    cout<<rs;
    return 0;
}