QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604310#6443. Windblume FestivalLJY_ljyWA 55ms3848kbC++111.0kb2024-10-02 09:22:422024-10-02 09:22:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 09:22:43]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:3848kb
  • [2024-10-02 09:22:42]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std; 

const long long MAXN = 1e6 + 10;

inline long long read() {
	long long x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

long long n, a[MAXN];

int main() {
	long long t = read();
	for (long long u = 1; u <= t; u++) {
		n = read();
		bool flag = false;
		for (long long i = 1; i <= n; i++) {
			a[i] = read();
			if (a[i] <= 0) flag = true;
		}
		if (flag) {
			long long ans = 0;
			for (long long i = 1; i <= n; i++) {
				ans += abs(a[i]);
			}
			printf("%lld\n", ans);
		} else if (n > 1) {
			sort(a + 1, a + 1 + n);
			long long ans = 0;
			for (long long i = 2; i <= n; i++) ans += a[i];
			ans -= a[1];
			printf("%lld\n", ans);
		} else {
			printf("%lld\n", a[1]);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4
1 -3 2 -4
11
91 66 73 71 32 83 72 79 84 33 93
12
91 66 73 71 32 83 72 79 84 33 33 93
13
91 66 73 71 32 83 72 79 84 33 33 33 93
1
0

output:

10
713
746
779
0

result:

ok 5 number(s): "10 713 746 779 0"

Test #2:

score: -100
Wrong Answer
time: 55ms
memory: 3772kb

input:

1000000
1
2
1
-2
1
1
1
-1
1
2
1
1
1
2
1
-2
1
-2
1
2
1
1
1
1
1
2
1
2
1
2
1
-2
1
-2
1
0
1
2
1
1
1
-1
1
0
1
-2
1
0
1
1
1
1
1
-2
1
-2
1
2
1
1
1
2
1
1
1
1
1
0
1
2
1
0
1
-1
1
-1
1
-2
1
-2
1
0
1
-2
1
0
1
1
1
-1
1
2
1
0
1
-2
1
-2
1
0
1
1
1
-1
1
-2
1
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
1
1
2
1
0
1
0
1
-2
1
2
1
2
1
...

output:

2
2
1
1
2
1
2
2
2
2
1
1
2
2
2
2
2
0
2
1
1
0
2
0
1
1
2
2
2
1
2
1
1
0
2
0
1
1
2
2
0
2
0
1
1
2
0
2
2
0
1
1
2
1
0
1
1
1
1
1
2
0
0
2
2
2
1
2
2
1
2
1
2
2
1
1
0
2
0
0
0
1
1
2
1
1
0
2
1
2
1
1
0
1
2
2
1
1
0
2
2
2
1
0
1
0
1
0
1
2
2
1
2
2
0
1
1
1
2
2
2
1
1
2
0
2
2
2
1
0
1
0
1
2
2
1
2
1
1
0
1
1
1
0
2
2
1
0
2
0
...

result:

wrong answer 2nd numbers differ - expected: '-2', found: '2'