Submission #201664

#TimeUsernameProblemLanguageResultExecution timeMemory
201664SamAndPareto (COCI17_pareto)C++17
80 / 80
77 ms3088 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...