Advertisement
Manioc

arrumando

Oct 22nd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
  3.  
  4. using namespace std;
  5.  
  6. typedef struct trab{
  7.         int v, t;
  8. } trab;
  9.  
  10. int compare(trab a, trab b){
  11.     return a.t < b.t;
  12.  }
  13.    
  14. int main(){
  15.  
  16.     optimizar_io;
  17.  
  18.     int N, H;
  19.     while (cin >> N >> H){
  20.         trab arr[N];
  21.  
  22.         for(int i = 0; i < N ; i++) {
  23.             cin >> arr[i].v >> arr[i].t;
  24.         }
  25.         qsort(arr, N, sizeof(trab), compare);
  26.  
  27.         trab entryByHour[H+1];
  28.         int loss = 0;
  29.         for(int i=0;i<N;i++){
  30.  
  31.             int j= arr[i].t-1;
  32.  
  33.             while(j>=0 && entryByHour[j].t != NULL) j--;
  34.  
  35.             if(j < 0) loss += arr[i].v;
  36.             else entryByHour[j] = arr[i];
  37.         }          
  38.         cout << loss << endl;
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement