Cod sursa(job #2294696)

Utilizator slym777Darii Dan slym777 Data 2 decembrie 2018 18:17:09
Problema Lupul Urias si Rau Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

ifstream fin("lupu.in");
ofstream fout("lupu.out");

vector <pii> v;

//bool cmp(pii a,pii b)
//{
  //  return a.first > b.first;
//}

int main()
{
    int n,x,L;
    long long lana = 0;
    fin >> n >> x >> L;
    for (int i = 0; i< n; i++)
    {
        int a,b;
        fin >> a >> b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    //for (auto a:v)
        //cout << a.first << " " << a.second << "\n";
    multiset <int, greater<int> > Q;
    int d = (x%L);
    int i = 0;
    while (v[i].first > d)
            {
                d += L;
            }
    while (v[i].first <= d && d <= x)
    {
        Q.insert(v[i].second);
        if (v[i+1].first > d || i == n-1)
        {
            ///for (auto a:Q)
            ///    cout << a << " ";
            ///    cout << "\n";
            lana += *Q.begin();
            ///cout << "am ales \n" << i << ": " << d << " " << *Q.begin() << "\n";
            d +=L;
            Q.erase(Q.begin());
            for (auto a:Q)
                cout << a << " ";
                cout << "\n";
            while (v[i+1].first > d)
            {
                if (!Q.empty())
                {
                    lana += *Q.begin();
                    Q.erase(Q.begin());
                }
                d += L;
            }
        }
        i++;
    }
    fout << lana;
    return 0;
}