QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389219 | #4373. Swap Space | TWTP_TCTF# | WA | 1ms | 3872kb | C++20 | 1.1kb | 2024-04-14 06:56:39 | 2024-04-14 06:56:39 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define rep(i, a, b) for(int i = a ; i < b ; i ++)
#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void doWork() {
int n;
cin >> n;
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
}
sort(v.begin(), v.end(), [&](pair<int, int> a, pair<int, int> b) {
if (a.second - a.first >= 0 && b.second - b.first >= 0) {
return a.first < b.first;
}
if (a.second - a.first < 0 && b.second - b.first < 0) {
a.second - b.first > b.second - a.first;
}
return a.second > b.second;
});
ll ans = 0;
ll cur = 0;
for (auto i: v) {
cur -= i.first;
ans = min(ans, cur);
cur += i.second;
}
cout << -ans;
}
int main() {
IO
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
4 6 6 1 7 3 5 3 5
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 2 2 3 3 5 1 5 10
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 42 41
output:
42
result:
ok single line: '42'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
5 3000 500000 20 21 20 100 4000 4001 4000 4100
output:
2919
result:
ok single line: '2919'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
5 2000 1999 20 1 20 19 3500 1000 5000 4000
output:
5000
result:
ok single line: '5000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
5 40 35 30 30 1000 1000 50 50 35 40
output:
995
result:
ok single line: '995'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3872kb
input:
10 2 4 2 2 4 2 2 10 5 5 4 2 6 2 4 7 10 8 5 4
output:
10
result:
wrong answer 1st lines differ - expected: '2', found: '10'