#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
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<long long int> v(n),p(n) ;long long 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<<a<<"\n";
cout<<h;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
18 ms |
1876 KB |
Output is correct |
7 |
Correct |
29 ms |
3412 KB |
Output is correct |
8 |
Correct |
45 ms |
4948 KB |
Output is correct |