Skip to content

Instantly share code, notes, and snippets.

@danielsaad
Created May 13, 2016 15:55
Show Gist options
  • Save danielsaad/914508bb19e016672a3fe2efe2aafcf4 to your computer and use it in GitHub Desktop.
Save danielsaad/914508bb19e016672a3fe2efe2aafcf4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class valorHora{
public:
int valor;
int hora;
};
struct ordePrimCol{
bool operator()(const valorHora& lhs, const valorHora& rhs) const{
if(lhs.valor > rhs.valor){
return true;
}
if(lhs.valor == rhs.valor){
return lhs.hora > rhs.hora;
}
return false;
}
};
int main(){
ios::sync_with_stdio(false);
int n = 0, h = 0;
while(cin >> n >> h){
int resto = 0, x = 0, y = 0, menor = 0;
vector<valorHora> th(n);
vector<bool> tarefas(h, false);
for(int i = 0; i < n; i++){
cin >> x >> y;
th[i].valor = x;
th[i].hora = y;
resto += x;
}
sort(th.begin(), th.end(), ordePrimCol());
for(int l = 0; l < n; l++){
menor = min(h, th[l].hora);
for(int k = menor - 1; k >= 0; k--){
if(tarefas[k] == false){
tarefas[k] = true;
resto -= th[l].valor; //VOCÊ TINHA COLOCADO th[k]
break;
}
}
}
cout << resto << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment