Advertisement
YEZAELP

PROG-1075: หนอน (worm)

Jun 8th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using lli=long long ;
  4. const lli INF=1e9;
  5. using pii=pair<lli,lli>;
  6. int main(){
  7.  
  8.     int n;
  9.     scanf("%d",&n);
  10.     pii ar[n+1];
  11.     for(int i=1;i<=n;i++){
  12.         lli x,y;
  13.         scanf("%lld %lld",&x,&y);
  14.         ar[i]={y,x};
  15.     }
  16.     sort(ar+1,ar+n+1);
  17.     long long sum=0,fire=0,sum_max;
  18.     double mx=0.0;
  19.     for(int i=1;i<=n;i++){
  20.         sum+=ar[i].second;
  21.         if(sum/(double)ar[i].first>mx) {
  22.             mx=(double)sum/ar[i].first;
  23.             sum_max=sum;
  24.             fire=ar[i].first;
  25.         }
  26.  
  27.     }
  28.     printf("%lld %lld",sum_max,fire);
  29.  
  30.     return 0;
  31. }
  32. /*
  33. 5
  34. 3 30
  35. 6 10
  36. 10 20
  37. 7 50
  38. 18 70
  39. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement