QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875221 | #4373. Swap Space | kevinyang | WA | 1ms | 3712kb | C++17 | 860b | 2025-01-29 13:21:02 | 2025-01-29 13:21:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
bool comp(pii a, pii b){
return min(-a.first,-a.first+a.second-b.first) > min(-b.first,-b.first+b.second-a.first);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<pii>a(n+1);
for(int i = 1; i<=n; i++){
cin >> a[i].first >> a[i].second;
}
sort(a.begin(),a.end(),comp);
int cur = 0;
int mn = 0;
for(int i = 1; i<=n; i++){
//cout << a[i].first << '\n';
cur -= a[i].first;
mn = min(mn,cur);
cur += a[i].second;
}
cout << abs(mn) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3584kb
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: 3584kb
input:
1 42 41
output:
42
result:
ok single line: '42'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
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: 3712kb
input:
5 2000 1999 20 1 20 19 3500 1000 5000 4000
output:
5000
result:
ok single line: '5000'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3584kb
input:
5 40 35 30 30 1000 1000 50 50 35 40
output:
1000
result:
wrong answer 1st lines differ - expected: '995', found: '1000'