QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#242673#7339. A Really Odd SequencePetroTarnavskyi#AC ✓214ms3620kbC++20853b2023-11-07 16:15:482023-11-07 16:15:49

Judging History

This is the latest submission verdict.

  • [2023-11-07 16:15:49]
  • Judged
  • Verdict: AC
  • Time: 214ms
  • Memory: 3620kb
  • [2023-11-07 16:15:48]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const LL LINF = 1.01e18;

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0);
	cout << fixed << setprecision(15);
	int t;
	cin >> t;
	while (t--)
	{
		LL minPref[2] = {0, LINF};
		int n;
		cin >> n;
		LL s = 0, ans = -LINF;
		FOR(i, 1, n + 1)
		{
			int a;
			cin >> a;
			s += a;
			minPref[i & 1] = min(minPref[i & 1], s);
			ans = max(ans, s - minPref[(i & 1) ^ 1]);
		}
		cout << ans << "\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

input:

1
4
8 -7 9 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 214ms
memory: 3620kb

input:

59056
10
0 1 1 0 1 0 1 1 1 0
10
-1 -1 -1 1 0 0 1 0 0 1
10
1 0 0 1 1 1 -1 -1 0 1
10
-1 1 -1 1 0 1 1 0 -1 1
10
1 0 0 1 -1 0 -1 -1 -1 1
10
1 1 1 0 0 -1 -1 1 0 0
10
-1 1 0 0 1 -1 -1 0 -1 -1
10
1 -1 0 0 0 -1 -1 -1 -1 -1
10
0 0 0 1 1 0 0 1 -1 1
10
0 -1 0 0 1 0 1 1 1 0
10
0 0 0 0 1 -1 1 -1 -1 -1
10
-1 0 1 ...

output:

6
3
3
3
1
3
1
1
3
4
1
2
3
6
1
1
4
2
1
1
4
1
3
2
3
1
5
1
1
2
3
1
1
2
2
3
0
5
1
1
2
1
1
2
3
2
1
2
1
3
1
2
3
2
3
2
3
2
5
1
3
2
2
2
2
1
1
2
2
3
2
1
3
1
2
1
1
2
2
1
2
1
1
3
1
3
1
1
2
1
2
2
3
2
1
2
1
1
3
3
1
1
2
1
1
3
1
2
2
1
1
1
3
3
2
1
3
2
3
2
2
4
2
1
2
4
3
5
2
2
4
1
1
2
1
1
2
2
5
3
3
0
2
2
2
1
1
2
1
2
...

result:

ok 59056 numbers