Submission #4101440


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int max(int a, int b) { return (a > b) ? a : b; }

const int MAXN = 100000;

int a[MAXN];
int b[MAXN];


const int INF = 1e9;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<int, int>> v;
    v.reserve(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        v.emplace_back(a[i] + b[i], i);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int i = 1;
    ll ans = 0;
    for (auto& p : v)
    {
        if (i == 1)
        {
            ans += a[p.second];
            i = 0;
        } else
        {
            i = 1;
            ans -= b[p.second];
        }
    }

    cout << ans;
    return 0;
}

Submission Info

Submission Time
Task C - Different Strokes
User DDos
Language C++14 (GCC 5.4.1)
Score 400
Code Size 824 Byte
Status AC
Exec Time 31 ms
Memory 1792 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KiB
a02 AC 1 ms 256 KiB
a03 AC 1 ms 256 KiB
b04 AC 1 ms 256 KiB
b05 AC 21 ms 1792 KiB
b06 AC 21 ms 1792 KiB
b07 AC 31 ms 1792 KiB
b08 AC 29 ms 1792 KiB
b09 AC 29 ms 1792 KiB
b10 AC 28 ms 1792 KiB
b11 AC 28 ms 1792 KiB
b12 AC 28 ms 1792 KiB
b13 AC 29 ms 1792 KiB