QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771476 | #8057. Best Carry Player 4 | yuanruiqi# | WA | 70ms | 3768kb | C++14 | 1.7kb | 2024-11-22 13:22:10 | 2024-11-22 13:22:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
void solve()
{
int n;
cin >> n;
map<i64, i64> s, ss, t;
for (int i=0;i<n;++i)
{
int x;
cin >> x;
if (x) s[i] = x;
}
for (int i=0;i<n;++i)
{
int x;
cin >> x;
if (x) t[i] = x;
}
s[0] = 0x3f3f3f3f3f3f3f3f; t[0] = 0x3f3f3f3f3f3f3f3f;
map<pii, i64> mp;
while (s.size() && t.size())
{
while (s.size() && s.begin()->first + t.rbegin()->first < n - 1)
{
ss.insert(*s.begin());
s.erase(s.begin());
}
if (!s.size()) break;
i64 k = min(s.begin()->second, t.rbegin()->second);
mp[pii(s.begin()->first, t.rbegin()->first)] += k;
if (s.begin()->second == k) s.erase(s.begin()); else s.begin()->second -= k;
if ((--t.end())->second == k) t.erase(--t.end()); else (--t.end())->second -= k;
}
i64 ms = 0, mt = 0;
for (auto [x, y] : s) ms = max(ms, x);
for (auto [x, y] : ss) ms = max(ms, x);
for (auto [x, y] : t) mt = max(mt, x);
int ok = 0;
i64 sum = 0;
for (auto [p, x] : mp) sum += x;
for (auto [p, x] : mp)
if (max(p.first, ms) + max(p.second, mt) >= n)
{
ok = 1;
break;
}
if (ok) return cout << sum << '\n', void();
ms = mt = 0;
for (auto [p, x] : mp) ms = max(ms, p.first), mt = max(mt, p.second);
if (ms + mt < n) return cout << "0\n", void();
cout << sum - 1 << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
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: 3552kb
input:
5 2 1 2 3 4 3 1 0 1 0 1 0 4 1 0 0 1 1 1 1 1 5 123456 114514 1919810 233333 234567 20050815 998244353 0 0 0 10 5 3 5 3 2 4 2 4 1 5 9 9 8 2 4 4 3 5 3 0
output:
5 1 2 467900 29
result:
ok 5 number(s): "5 1 2 467900 29"
Test #2:
score: -100
Wrong Answer
time: 70ms
memory: 3768kb
input:
100000 5 0 1 1 1 1 0 0 1 0 0 5 0 0 0 0 0 1 1 1 0 0 5 0 0 2 1 1 0 2 1 0 1 5 0 0 0 0 0 1 2 1 0 0 5 0 1 0 1 1 0 0 1 1 1 5 2 0 0 0 1 1 0 0 0 3 5 2 0 0 1 1 0 2 1 1 1 5 0 0 0 0 2 0 0 0 0 1 5 0 0 0 0 0 0 1 1 0 0 5 4 0 0 0 0 0 0 0 1 0 5 0 0 0 0 1 2 1 1 0 0 5 0 2 3 0 0 0 0 0 1 0 5 1 1 1 0 1 1 0 1 0 1 5 0 0 0...
output:
2 0 4 0 4 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 4 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 2 2 2 0 4 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 1 1 2 0 3 4 0 2 5 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 2 1 1 0 1 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 1 0 2 2 3 0 1 2 0 1 1 ...
result:
wrong answer 5th numbers differ - expected: '3', found: '4'