QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693953#6443. Windblume FestivalnageingWA 112ms3852kbC++20928b2024-10-31 17:01:182024-10-31 17:01:19

Judging History

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

  • [2024-10-31 17:01:19]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:3852kb
  • [2024-10-31 17:01:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 2E5 + 10, mod = 1E9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	bool have1 = 0, have2 = 0;
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		if (a[i] <= 0) have1 = 1;
		if (a[i] >= 0) have2 = 1;
	}
	ll ans = 0;
	if (have1 && have2) {
		for (int i = 0; i < n; i ++) {
			ans = ans + abs(a[i]);
		}
	} else if (have2) {
		sort(a.begin(), a.end());
		for (int i = 1; i < n; i ++) {
			ans = ans + a[i];
		}
		ans = ans - a[0];
	} else {
		sort(a.begin(), a.end(), [&](int x, int y) {
			return x > y;
		});
		for (int i = 1; i < n; i ++) {
			ans = ans - a[i];
		}
		ans = ans + a[0];
	}
	cout << ans << '\n';
} 

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t --) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 112ms
memory: 3852kb

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
...

result:

wrong answer 1st numbers differ - expected: '2', found: '-2'