Cod sursa(job #1050803)

Utilizator vlady1997Vlad Bucur vlady1997 Data 9 decembrie 2013 10:08:22
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
        #include <cstdio>
        #include <algorithm>
        #include <vector>
        #include <set>
        #define pb push_back
        #define mp make_pair
        #define f first
        #define s second
        using namespace std;
        multiset < pair <int,int> > h;
        vector < pair <int,int> > a;
        pair <int,int> X;
        multiset < int > :: iterator it;
        int b[100001], c[100001];
        int main()
        {
            int n, x, l, m=0, i, d, e, S=0;
            freopen("lupu.in","r",stdin);
            freopen("lupu.out","r",stdout);
            scanf("%d%d%d",&n,&x,&l);
            for (i=1; i<=n; i++)
            {
                scanf("%d%d",&d,&e);
                if (d<=x) {b[++m]=d; c[m]=e;}
            }
            for (i=1; i<=m; i++)
            {
                int z=(x-i+1)/l;
                a.pb(mp(z,c[i]));
            }
            sort(a.begin(), a.end());
            reverse(a.begin(), a.end());
            for (i=m; i>=1; i++)
            {
                h.insert(mp(a[i].f,a[i].s));
                X=*(h.begin()); S+=X.f;
                h.erase(i);
            }
            fclose(stdin);
            fclose(stdout);
            return 0;
        }