Submission #201664

# Submission time Handle Problem Language Result Execution time Memory
201664 2020-02-11T16:33:59 Z SamAnd Pareto (COCI17_pareto) C++17
80 / 80
77 ms 3088 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;

int n;
int a[N];

int main()
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(14);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    long double sum = 0;
    for (int i = 1; i <= n; ++i)
        sum += a[i];
    long double ans1 = 1, ans2 = 1;
    long double p = 0;
    for (int i = 1; i <= n; ++i)
    {
        p += a[i];
        long double yans1 = (i * 1.0) / n;
        long double yans2 = p / sum;
        if ((yans2 - yans1) > (ans2 - ans1))
        {
            ans1 = yans1;
            ans2 = yans2;
        }
    }
    cout << ans1 * 100 << endl << ans2 * 100 << endl;
    return 0;
}

Compilation message

pareto.cpp: In function 'int main()':
pareto.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
pareto.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 8 ms 504 KB Output is correct
6 Correct 28 ms 1272 KB Output is correct
7 Correct 54 ms 2296 KB Output is correct
8 Correct 77 ms 3088 KB Output is correct