Блог пользователя aTSL

Автор aTSL, история, 3 года назад, По-английски

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;
}
/*

*/
  • Проголосовать: нравится
  • -20
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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