P2123-皇后游戏

这题...一言难尽

 1 #include <bits/stdc++.h>
 2 #define maxn 13003
 3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 4 typedef long long ll;
 5 using namespace std;
 6 
 7 inline ll read()
 8 {
 9     ll ans = 0;
10     char ch = getchar(), last = ' ';
11     while(!isdigit(ch)) last = ch, ch = getchar();
12     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
13     if(last == '-') ans = -ans;
14     return ans;
15 }
16 inline void write(ll x)
17 {
18     if(x < 0) x = -x, putchar('-');
19     if(x >= 10) write(x / 10);
20     putchar(x % 10 + '0');
21 }
22 int T,n;
23 struct chen
24 {
25     ll a;
26     ll b;
27 };
28 chen per[20004];
29 ll c[20004];
30 ll suma[20004];
31 bool cmp(chen x,chen y)
32 {
33     return min(x.a,y.b)==min(y.a,x.b)?x.a<y.a:min(x.a,y.b)<min(y.a,x.b);
34 }
35 
36 int main()
37 {
38     T = read();
39     while(T--)
40     {
41         n = read();
42         _for(i,1,n+1)
43             per[i].a = read(),per[i].b = read();
44         sort(per+1,per+1+n,cmp);
45         _for(i,1,n+1)
46             suma[i] = suma[i-1] + per[i].a;
47         _for(i,1,n+1)
48             c[i] = max(c[i-1],suma[i]) + per[i].b;
49         write(c[n]);
50         printf("\n");
51     }
52     return 0;
53 }

 

posted @ 2019-08-15 17:25  Asurudo  阅读(155)  评论(0编辑  收藏  举报