Submission #599705

# Submission time Handle Problem Language Result Execution time Memory
599705 2022-07-19T19:15:31 Z f1nder Pareto (COCI17_pareto) C++17
0 / 80
3 ms 596 KB
#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
 
   #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("error.txt", "w", stderr);
   freopen("output.txt", "w", stdout);
   #endif
   
int t=1;
while(t--)
{
	solve();
	cout<<"\n";
}

cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}
void solve()
{
    int n;cin>>n;
    std::vector<int> v(n),p(n) ;int sum=0;
    for (int i = 0; i < n; i++) {
        /* code */
        cin>>v[i];sum+=v[i];
    }
    sort(v.rbegin(),v.rend());
    double hi=0.0;double ai;
    p[0]=v[0];double h=(((v[0])*100.0)/sum);double a=(100.0)/n;
    for (int i = 1; i <= n; i++) {
        /* code */
        p[i]+=p[i-1]+v[i];
         hi=(p[i]*100.0)/sum;
        ai=((i+1)*100.0)/n;
        //cout<<" "<<h<<" "<<a;
        if((hi-ai)>(h-a)) {h=hi;a=ai;}
    }
    cout<<fixed<<setprecision(1)<<a<<"\n";
    cout<<setprecision(14);
    cout<<h;
    
}	

Compilation message

pareto.cpp: In function 'int main()':
pareto.cpp:9:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |    freopen("input.txt", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
pareto.cpp:10:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |    freopen("error.txt", "w", stderr);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
pareto.cpp:11:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |    freopen("output.txt", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 596 KB Execution killed with signal 11
2 Runtime error 2 ms 596 KB Execution killed with signal 11
3 Runtime error 2 ms 596 KB Execution killed with signal 11
4 Runtime error 3 ms 596 KB Execution killed with signal 11
5 Runtime error 2 ms 596 KB Execution killed with signal 11
6 Runtime error 2 ms 596 KB Execution killed with signal 11
7 Runtime error 2 ms 596 KB Execution killed with signal 11
8 Runtime error 2 ms 596 KB Execution killed with signal 11