Cod sursa(job #2329887)

Utilizator gabiluciuLuciu Gabriel gabiluciu Data 27 ianuarie 2019 17:16:26
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.6 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
int n, x, l, dist, a, lana;

int main() {
    ios_base::sync_with_stdio(false);
    //clock_t tStart = clock();
    cin >> n >> x >> l;
    map<int, int> m;//,greater<>> s;
    while (n--) {
        cin >> dist >> lana;
        int nrp = abs(x - dist) / l + ((abs(x - dist) % l) != 0);
        if (dist + l * nrp == x) ++nrp;
        if (dist + l * (nrp - 1) <= x) {
            if (m.find(nrp) != m.end()) {
                m[nrp] = max(m[nrp], lana);
            } else {
                m.insert({nrp, lana});
            }
        }
    }
    ull sum = 0;
    for (auto it = m.begin(); it != m.end(); ++it) {
//        cout << it->first << ' '<< it->second << nl;
        sum += it->second;
    }
    cout << sum << nl;
    cout.close();
    //printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}