QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#525137 | #7523. Partially Free Meal | rxzfn639 | WA | 302ms | 32940kb | C++23 | 1.2kb | 2024-08-20 13:17:26 | 2024-08-20 13:17:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
void solve() {
int n;
cin >> n;
vector<i64> a(n), b(n), ans(n);
i64 res = 0, mxb = 0;
set<pair<i64, int>> sa, sb;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sa.insert({a[i], i});
sb.insert({b[i], i});
res += a[i];
mxb = max(mxb, b[i]);
}
res += mxb;
ans[n - 1] = res;
for (int i = n - 2; i >= 0; i--) {
auto tmp1 = *sa.rbegin();
auto tmp2 = *sb.rbegin();
auto tmp3 = *prev(prev(sb.end()));
i64 res1 = tmp1.first, res2 = a[tmp2.second] + b[tmp2.second] - b[tmp3.second];
if (res1 > res2) {
ans[i] = ans[i + 1] - res1;
sa.erase(tmp1);
sb.erase({b[tmp1.second], tmp1.second});
} else {
ans[i] = ans[i + 1] - res2;
sb.erase(tmp2);
sa.erase({a[tmp2.second], tmp2.second});
}
}
for (int i = 0; i < n; i++) {
cout << ans[i] << '\n';
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
/*
3
2 5
4 3
3 7
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 302ms
memory: 32940kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
24398492 29530803 41285117 43244479 46923198 63589998 83594070 84443369 95239774 102594890 132067022 161834077 176269413 182037762 225531400 284240164 307893407 334981118 384843467 388529211 392318074 397466199 428368332 468884810 483158396 498452466 505842099 515548541 534338016 534686397 576558806...
result:
wrong answer 1st lines differ - expected: '1318594', found: '24398492'