QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389220#4373. Swap SpaceTWTP_TCTF#WA 0ms3588kbC++201.1kb2024-04-14 06:57:372024-04-14 06:57:37

Judging History

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

  • [2024-04-14 06:57:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-04-14 06:57:37]
  • 提交

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) {
            return 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();
    }
}

詳細信息

Test #1:

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

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

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

input:

1
42 41

output:

42

result:

ok single line: '42'

Test #4:

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

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

input:

5
2000 1999
20 1
20 19
3500 1000
5000 4000

output:

5500

result:

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