Submission #26024

# Submission time Handle Problem Language Result Execution time Memory
26024 2017-06-26T14:34:19 Z iletavcioski Pareto (COCI17_pareto) C++14
80 / 80
166 ms 14508 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long double ll;
int main()
{
	ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    ll brojac=0;
    vector<ll> v;
    for(int i=0;i<n;i++)
    {
        ll a;
        cin>>a;
        v.push_back(a);
        brojac+=a;
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    int broj=0;
    double d1;
    double d2;
    double maxi=-1;
    ll broj1=0;
    for(int i=0;i<v.size();i++)
    {
        broj1+=v[i];
        broj++;
        double dd=(double)broj/(double)n;
        double ddd=(ll)broj1/(ll)brojac;
        if(maxi<abs(ddd-dd))
        {
            maxi=abs(ddd-dd);
            d1=dd;
            d2=ddd;
        }
    }
    d1*=100;
    d2*=100;
    cout<<fixed<<setprecision(14);
    cout<<d1<<endl;
    cout<<fixed<<setprecision(14);
    cout<<d2<<endl;
 
    return 0;
}

Compilation message

pareto.cpp: In function 'int main()':
pareto.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++)
                  ^
pareto.cpp:43:12: warning: 'd2' may be used uninitialized in this function [-Wmaybe-uninitialized]
     d2*=100;
            ^
pareto.cpp:42:12: warning: 'd1' may be used uninitialized in this function [-Wmaybe-uninitialized]
     d1*=100;
            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2600 KB Output is correct
6 Correct 46 ms 5292 KB Output is correct
7 Correct 96 ms 8364 KB Output is correct
8 Correct 166 ms 14508 KB Output is correct