Cod sursa(job #2443961)

Utilizator red_devil99Mancunian Red red_devil99 Data 29 iulie 2019 21:14:45
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;


bool sortbysec(pair<int,int> &a, 
              pair<int,int> &b) 
{ 
    return (a.first > b.first); 
} 

int main(){
	ifstream fin("lupu.in");
    ofstream fout("lupu.out");
	int n, x, l, d, lana;
	fin >> n >> x >> l;
	vector<pair<int, int>> v;
	for(int i = 0; i < n; i++){
		fin >> d >> lana;
		v.push_back(make_pair(d, lana));
		
	}
   sort(v.begin(), v.end(), sortbysec);
   int copie = v[n-1].first;
   //fout << copie <<'\n';
   int pas = 0;
   while(copie <= x){
      pas++;
      copie += l;
   }
   int max = 0;
   int nr = 0;
   int S = 0;
   //fout << pas<<'\n';
   std::vector<int> vec;
  while(pas){ 
   max = 0;
   nr = 0;
   for(int i = 0; i < n; i++){
   	if(v[i].first + l > x){
   	   nr++;
       vec.push_back(v[i].second);
   	}else{
   		continue;
   	}
   }
   max = *max_element(vec.begin(), vec.end());
   vec.clear();
   v.erase(v.begin(), v.begin() + nr);
   for(int i = 0; i < n; i++){
   	v[i].first += l;
   }
   n -= nr;
   S += max;
   pas--;
}
fout << S <<" ";
}