Cod sursa(job #2329962)

Utilizator gabiluciuLuciu Gabriel gabiluciu Data 27 ianuarie 2019 18:29:49
Problema Lupul Urias si Rau Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
/*
ID: gabriel100
LANG: C++
TASK:
*/
#include <cstdio>
#include <algorithm>
//#include <time.h>
#include <queue>
#include <cmath>
#include <stack>
#include <fstream>
#include <bitset>
#include <set>
#include <map>

#define nl '\n'
#define F first
#define S second
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define eb(x) emplace_back(x)
#define ull unsigned long long
#define ll long long
#define ProblemName "lupu"
#define LocalName "data"
#ifdef INFOARENA
#define Filename ProblemName
#else
#define Filename LocalName
#endif
#define Input Filename".in"
#define Output Filename".out"
using namespace std;
ifstream cin(Input);
ofstream cout(Output);

template<class a, class type>
void print(a v, type t) {
    for_each(all(v), [](type x) { cout << x << ' '; });
    cout << nl;
}

#define N 10
vector<pair<int,int> > ms(100001);
int n, x, l, dist, lana;
int main() {
    ios_base::sync_with_stdio(false);
    //clock_t tStart = clock();
    cin >> n >> x >> l;
    for(int i=0;i<n;++i){
        cin >> ms[i].first >> ms[i].second;
    }
    sort(ms.begin(),ms.begin()+n);
    int ans = 0;
    priority_queue<int> p;
    for(int t=x%l,i=0;t<=x;t+=l){
        while(i<n && (ms[i].first) <= t) {
            p.push(ms[i].second);
            ++i;
        }
        if(!p.empty())
            ans += p.top(),p.pop();
    }
    cout << ans;
    cout.close();
    //printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}