Advertisement
Diene

Untitled

Dec 25th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct encomenda{
  6.     int conf, entre;
  7. };
  8.  
  9. bool ordem(encomenda a, encomenda b){
  10.     return a.entre<=b.entre;
  11. }
  12.  
  13. int main(){
  14.  
  15.     int n,t=0,s=0;
  16.     encomenda pedido[10010];
  17.     scanf("%d",&n);
  18.     for(int i=1;i<=n;i++){
  19.         scanf("%d%d", &pedido[i].conf,&pedido[i].entre);
  20.     }
  21.     sort(pedido+1,pedido+1+n,ordem);
  22.     for(int i=1;i<=n;i++){
  23.         if(s+pedido[i].conf<= pedido[i].entre){
  24.             s=s+pedido[i].conf;
  25.         }
  26.         else{
  27.             t=t+(s+pedido[i].conf-pedido[i].entre);
  28.             s=s+pedido[i].conf;
  29.         }
  30.     }
  31.     printf("%d", t);
  32.     return 0;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement