QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#696684 | #6695. Matching | pppwolf# | WA | 0ms | 3564kb | C++23 | 792b | 2024-11-01 00:27:22 | 2024-11-01 00:27:22 |
Judging History
answer
#include <bits/stdc++.h>
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
void solve() {
int n;
std::cin >> n;
std::vector<i64> a(n + 1);
std::map<i64, std::vector<i64>> mp;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
mp[a[i] - i].push_back(a[i]);
}
i64 ans = 0;
for (auto [x, v] : mp) {
if (v.size() < 2) {
continue;
}
sort(v.begin(), v.end(), std::greater());
for (int i = 0; i < v.size(); i += 2) {
if (v[i + 1] + v[i] > 0) {
ans += v[i + 1] + v[i];
} else {
break;
}
}
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 9 3 -5 5 6 7 -1 9 1 2 3 -5 -4 -3 3 1 10 100
output:
101138 0 0
result:
wrong answer 1st numbers differ - expected: '30', found: '101138'