杭电1422 ,看了很久不知道为啥还wa???

2024-12-16 16:04:24
推荐回答(1个)
回答1:


这个问题是最长连续非负子序列
但是因为带环, 所以要做循环处理
#include
#include

using namespace std;

int main(int argc, char *argv[])
{
int n, a, b;
while (scanf("%d", &n)!=EOF)
{
int i, j, res[100000], max=0, count=0,flag=0, temp=0;
for (i=0; i {
scanf("%d%d", &a, &b);
res[i] = a - b;
temp += res[i];
if (temp >= 0)
count++;
else
{
count = 0;
temp = 0;
}
if (count > max)
max = count;
}
for(i=0;i {
temp += res[i];
if (temp >= 0)
count++;
else
{
count = 0;
temp = 0;
}
if (count > max)
max = count;
}
printf("%d\n", max>n?n:max);
}
// system("PAUSE");
return EXIT_SUCCESS;
}