QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547667#4373. Swap SpaceJooDdaeWA 0ms3688kbC++20619b2024-09-05 01:22:312024-09-05 01:22:31

Judging History

你现在查看的是最新测评结果

  • [2024-09-05 01:22:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3688kb
  • [2024-09-05 01:22:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n;
vector<array<int, 2>> v[2];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++) {
        int a, b; cin >> a >> b;
        v[a <= b].push_back({a, b});
    }
    sort(v[1].begin(), v[1].end());

    ll ans = 0, cur = 0;
    for(auto [x, y] : v[1]) {
        if(cur < x) ans += x-cur, cur = x;
        cur += y-x;
    }

    sort(v[0].rbegin(), v[0].rend());
    for(auto [x, y] : v[0]) {
        if(cur < x) ans += x-cur, cur = x;
        cur += y-x;
    }

    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

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: 3640kb

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: 3688kb

input:

1
42 41

output:

42

result:

ok single line: '42'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

5
3000 500000
20 21
20 100
4000 4001
4000 4100

output:

2919

result:

ok single line: '2919'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3648kb

input:

5
2000 1999
20 1
20 19
3500 1000
5000 4000

output:

5500

result:

wrong answer 1st lines differ - expected: '5000', found: '5500'