Cod sursa(job #2329885)

Utilizator StefanZamfirStefan Zamfir StefanZamfir Data 27 ianuarie 2019 17:12:33
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.59 kb

/*


      _             _    ___     ___    _  __       __
   __| |   __ _    / |  / _ \   / _ \  (_)/ /    _  \ \
  / _` |  / _` |   | | | | | | | | | |   / /    (_)  | |
 | (_| | | (_| |   | | | |_| | | |_| |  / /_     _   | |
  \__,_|  \__,_|   |_|  \___/   \___/  /_/(_)   (_)  | |
                                                    /_/


 */

//#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#include <algorithm>
#include <bitset>
#include <time.h>
#include <tuple>
#include <fstream>
#include <iomanip>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>

#pragma warning "da 100% din tine. :)"
#define nl '\n'
#define cnl cout << '\n';
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ll long long
#define ull unsigned ll
#ifdef INFOARENA
#define ProblemName "lupu"
#endif
#define MCONCAT(A, B) A B
#ifdef ProblemName
#define InFile MCONCAT(ProblemName, ".in")
#define OuFile MCONCAT(ProblemName, ".out")
#else
#define InFile "a.in"
#define OuFile "a.out"
#endif


//using namespace __gnu_pbds;
using namespace std;
ifstream cin(InFile);
ofstream cout(OuFile);


//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

int X, L, N;
ll sum = 0;
int pas = 0;
int iter = 0;
int dmin = 0;

int main() {
    ios_base::sync_with_stdio(false);
    clock_t tStart = clock();
    cin.tie(nullptr);
    cin >> N >> X >> L;
    multiset<pair<int, int>, greater<> > oi;
    int D, A;
    for (int i = 0; i < N; ++i) {
        cin >> D >> A;
        oi.insert({A, D});
        dmin = min(dmin, D);
    }
    bool flag = 0;
    iter = (X - dmin) / L + 1;
    for (int pas = 0; pas < iter && !oi.empty(); ++pas) {
        flag = 0;
        for (auto it = oi.begin(); it != oi.end(); ++it) {
            if (it->second + L * (pas + 1) > X && it->second + L * pas <= X) {
                sum += it->first;
//                cout << it->first << ' ' << flag << nl;
                oi.erase(oi.find({it->first, it->second}));
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
//            cout << oi.begin()->first << ' ' << flag << nl;
            sum += oi.begin()->first;
            oi.erase(oi.find({oi.begin()->first, oi.begin()->second}));
        }
    }
    cout << sum << nl;
    printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}