Submission #660215

# Submission time Handle Problem Language Result Execution time Memory
660215 2022-11-21T07:13:34 Z ajthelegendcoder Pareto (COCI17_pareto) C++17
80 / 80
91 ms 2972 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> arr(n);
    double sum = 0;
    double cnt = 0;
    double taken = 0;
    double sumtaken = 0;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        sum += arr[i];
        cnt++;
    }
    
    sort(arr.begin(), arr.end());
    reverse(arr.begin(), arr.end());
    
    double maxt = 0, maxsum = 0;
    double range = 0;
    
    for(int i = 0; i < n; i++){
        taken++;
        sumtaken += arr[i];
        
        if(abs(taken/cnt * 100.0 - sumtaken/sum * 100.0) > range){
        maxt = max(maxt, taken/cnt * 100.0);
        maxsum = max(maxsum, sumtaken/sum * 100.0);
        range = abs(taken/cnt * 100.0 - sumtaken/sum * 100.0);
        
    }
    }
    cout << setprecision(16) << maxt << endl << maxsum << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 4 ms 404 KB Output is correct
6 Correct 30 ms 1208 KB Output is correct
7 Correct 64 ms 2216 KB Output is correct
8 Correct 91 ms 2972 KB Output is correct