Cod sursa(job #1412370)

Utilizator theprdvtheprdv theprdv Data 1 aprilie 2015 11:46:20
Problema Lupul Urias si Rau Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>

using namespace std;

fstream fin("lupu.in", ios::in);
fstream fout("lupu.out", ios::out);
#define MAXN 100005
int N, max_dist, total, steps, run;

class compare{
 public:
    bool operator()(pair <int, int> x, pair<int, int> y){
        if(x.first != y.first)
            return x.first < y.first;
        else return x.second < y.second;
    }
};
priority_queue <pair<int, int>, vector<pair<int, int> >, compare> heap;

void read()
{
    fin >> N >> max_dist >> run;
    for (int i=1, x, y; i<=N; i++)
        fin >> x >> y,
        heap.push(make_pair(y, x));
    fin.close();
}

int main()
{
    read();

    while(!heap.empty()){
        pair <int, int> node = heap.top();
        heap.pop();
        if(node.second + steps > max_dist) continue;

        total += node.first;
        steps += run;
    }
    fout << total << "\n";

    fout.close();
    return 0;
}