- January CSP算法基础赛
T3答案
- 2024-1-14 16:45:10 @
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[1000000];
void solve()
{
int n;
cin >> n;
int sum=0;
int ans=0;
for(int i=1; i<=n; i++)
{
cin >> a[i];
sum+=a[i];
}
if(sum%3!=0)
{
cout << "NO" << endl;
return;
}
sum=sum/3;
for(int i=1; i<=n; i++)
{
ans+=a[i];
if(ans>sum)
{
cout <<"NO" << endl;
return;
}
if(i==n and ans<sum)
{
cout << "NO" << endl;
return;
}
if(ans==sum)
{
ans=0;
}
}
cout << "YES" << endl;
}
signed main()
{
int t;
cin >> t;
while(t--)
{
solve();
}
return 0;
}
注:非老师做法!!!
0 comments
No comments so far...