QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179059#6895. a-b ProblemPPP#AC ✓72ms4564kbC++171012b2023-09-14 17:19:332023-09-14 17:19:34

Judging History

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

  • [2023-09-14 17:19:34]
  • 评测
  • 测评结果:AC
  • 用时:72ms
  • 内存:4564kb
  • [2023-09-14 17:19:33]
  • 提交

answer

#ifdef DEBUG
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const ll mod = 1000000007;
//const ll mod = 998244353;

#define X first
#define Y second

ll pew(ll a, ll b)
{
    ll res = 1;
    while (b>0)
    {
        if (b&1) res = res*a%mod;
        b >>= 1;
        a = a*a%mod;
    }
    return res;
}



void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll A = 0;
    for (ll i=0;i<n;i++)
    {
        ll x, y;
        cin >> x >> y;
        A += x;
        a[i] = y+x;
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for (ll i=1;i<n;i+=2)
    {
        A -= a[i];
    }
    cout << A << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifdef DEBUG
    //freopen("input.txt", "r", stdin);
//#endif
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 72ms
memory: 4564kb

input:

20
3
0 2
1 2
3 3
3
1 0
2 3
0 4
4
2 8
1 14
10 2
10 6
2
1 3
3 4
2
4 8
6 2
2
0 0
10 10
2
5 0
2 1
2
4 5
6 2
3
4 2
10 9
3 8
3
6 1
3 4
4 0
3
10 3
7 3
2 10
3
1 9
8 1
0 0
4
1 2
15 8
11 8
10 2
4
9 3
5 14
10 5
2 12
4
7 6
7 6
12 11
2 15
100000
3 1
10 8
1 8
7 9
3 6
9 2
0 7
1 3
7 1
2 0
10 9
2 5
0 3
6 1
9 0
1 1
1...

output:

1
-1
-2
0
2
10
4
2
6
6
7
0
15
-1
-2
-697
-24972584309703
24978641064563
42097360102
-61290555356

result:

ok 20 lines