QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#199658#6895. a-b ProblemhazeAC ✓35ms4480kbC++231005b2023-10-04 13:34:432023-10-04 13:34:45

Judging History

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

  • [2023-10-04 13:34:45]
  • 评测
  • 测评结果:AC
  • 用时:35ms
  • 内存:4480kb
  • [2023-10-04 13:34:43]
  • 提交

answer

#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
	char ch = getchar();
	ll s = 0; bool w = 0;
	while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
	while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return w ? - s : s;
}

const int itinf = 2e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;

int main(){
	int T = read();
	while(T --){
		int n = read();
		ll pre = 0;
		vector<ll>a(n);
		irep(i,0,n-1){
			int u = read(), v = read();
			pre -= v;
			a[i] = u + v;
		}
		sort(a.begin(), a.end());
		for(int i = n - 1; i >= 0; i -= 2)pre += a[i];
		printf("%lld\n", pre);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
memory: 4480kb

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