#5WA,查不出bug,求帮助
查看原帖
#5WA,查不出bug,求帮助
755114
CD43楼主2023/7/19 09:14
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int n;
int a[1000001];
int f[1000001];
int main()
{
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	int cnt=-1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]>0)f[i]=1;
		a[i]+=a[i-1];
		for(int j=1;j<=i-1;j++)
		{
			if(a[i]>=a[j]&&a[i]>=0&&a[j]>=0)
			{
				f[i]=max(f[i],f[j]+1);
			}
			
		}
		cnt=max(cnt,f[i]);
	}
	if(a[n]<0)
	{
		cout<<"Impossible";
	}
	else cout<<cnt<<endl;
	return 0;
	exit(0);
}
/*
1000000
<<fixed<<setprecision()

*/

in

50
1202
706
-1275
-1337
1847
1426
510
1160
-2186
-2417
2227
1160
1382
-189
2075
-932
-1291
-1617
-1326
391
-1594
1120
1214
-782
75
1887
2289
677
1688
119
-1977
-1676
-304
-1276
2080
-1923
1636
1946
-1744
1065
-1048
-1316
1365
1746
-448
-905
321
1252
-1396
-1106

out

8

my out

14
2023/7/19 09:14
加载中...