Advertisement
AlenAntonelli

Unija

Jun 27th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. /// Alen Antonelli, https://www.hackerrank.com/contests/contest-carinosito/challenges
  2. /// http://hsin.hr/coci/archive/2016_2017/contest5_tasks.pdf
  3. #include <iostream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     int n;
  13.     cin>>n;
  14.    
  15.     vector<int> v (n);
  16.     for(int i=0; i<n; i++)
  17.         cin>>v[i];
  18.    
  19.     sort(v.rbegin(), v.rend());
  20.    
  21.     double ST = 0;
  22.     for(int i=0; i<n; i++)
  23.         ST+=v[i];
  24.    
  25.     double sum=0, a, b;
  26.     double ma, mb;
  27.     for(int i=0; i<n; i++)
  28.     {
  29.         sum+=v[i];
  30.        
  31.         a = (double) (i+1)*100/n;
  32.         b = (sum*100/ST);
  33.        
  34.         if ( (b-a)>(mb-ma) )
  35.             ma=a, mb=b;
  36.         else break;
  37.     }
  38.     cout << setprecision(16) <<ma<<endl<<mb;
  39.    
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement