Codeforces and Polygon may be unavailable from May 23, 4:00 (UTC) to May 23, 7:00 (UTC) due to technical maintenance. ×

Aayuushh19's blog

By Aayuushh19, history, 21 month(s) ago, In English

https://codeforces.com/problemset/problem/1557/A

void solve(){ ll n;cin>>n; vll arr(n); FOR(i,0,n)cin>>arr[i]; double m=*max_element(all(arr)); double sum = accumulate(all(arr),0); sum=sum-m; double avg = sum/(n-1);

cout<<fixed<<setprecision(10)<<m+avg<<endl;

}

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Make sure everything is double. It might be due to precission errors but the idea is correct

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    everything is double......

    • »
      »
      »
      21 month(s) ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Not n, neither te array i mean EVERYTHING becases that is how it works unfortunately

»
21 month(s) ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

wrong countertest, misread problem

»
21 month(s) ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

accumulate returns an integer value by default and due to constraints sum will overflow try 0ll instead of 0 in accumulate function and you are good to go.

Your code fails on
5 1000000000 1000000000 1000000000 1000000000 1000000000