Cod sursa(job #2568889)

Utilizator berlioz10Spiridon Dragos berlioz10 Data 4 martie 2020 10:19:30
Problema Paduri de multimi disjuncte Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> Q;
int d, k, n, i, lim, val, maxx;
long long s;
struct nod
{
    int x,y;
} v[100006];
int cmp(const nod a, const nod b)
{
    return a.x < b.x;
}
int main ()
{
    ifstream f("lupu.in");
    ofstream g("lupu.out");
    f >> n >> d >> k;
    for(i = 1; i <= n; i ++)
        f >> v[i].x >> v[i].y;
    sort(v + 1, v + n + 1, cmp);
    i = 1;
    for(lim = 0; lim <= d && i <= n; lim = lim + k)
    {
        maxx=0;
        for(i = i; i <= n && v[i].x <= lim; i ++)
            if(maxx<v[i].y)
                maxx=v[i].y;
        s=s+maxx;
    }
    g << s << "\n";
    return 0;
}