aTSL's blog

By aTSL, history, 4 weeks ago, In English

Codeforces Round #678 (Div. 2) A Reorder

My answer for test 1 is YES NO But the answer given to me in the evaluation machine is NO NO

MY CODE:

#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
const int N=100005;
int a[1005];
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int tt;cin>>tt;
	while(tt--) {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>a[i];
        sort(a+1,a+1+n);
        double sum=0.00;
        for(int i=1;i<=n;i++) {
            for(double j=i;j<=n;j++) {
                sum+=(double)a[(int)j]/j;
            }
        }
        if((int)sum==m) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
	}
    return 0;
}
/*

*/
 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by aTSL (previous revision, new revision, compare).

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

There is always some precision issue with floating time variables, try using condition like abs(sum-m)<0.5 in the last if statement.