Cod sursa(job #2399841)

Utilizator RazvanPanaiteRazvan Panaite RazvanPanaite Data 8 aprilie 2019 09:19:11
Problema Lupul Urias si Rau Scor 88
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
#define DMAX 100010

using namespace std;

ifstream fin("lupu.in");
ofstream fout("lupu.out");

struct bnc{
    long long int poz,val;
};


bnc V[DMAX];
priority_queue <long long int> pq;

long long int n,x,l,ans;

inline bool operator<(bnc x,bnc y){
    return x.poz<y.poz;
}

void citire();

int main(){
    long long int rms=1,k;
    citire();
    sort(V+1,V+n+1);
    k=x%l;
    while(k<=x){
          for(;V[rms].poz<=k;rms++)
              pq.push(V[rms].val);
          k+=l;
          if(pq.size()){
             ans+=pq.top();
             pq.pop();
          }
    }
    fout<<ans<<'\n';
}

void citire(){
    long long int i,x1,y1;
    fin>>n>>x>>l;
    for(i=1;i<=n;i++){
        fin>>x1>>y1;
        V[i].poz=x1;
        V[i].val=y1;
    }
}