[CodeForces 1030C] Cram Time 题解

写一篇题解。

(其实是FQ看了Errichto的讲解才懂的)

首先先找到x(x+1)<=a+b的最大x.

然后一定存在一种方案可以将1~x都读了。

证明:

我们从大到小枚举。

对于笔记i:

如果A剩下的时间>=i,那就把i读了。

否则,一定存在另一些笔记可以将A的时间用光。因为我们是从大到小枚举的。

所以最终情况一定是A时间被用光,所以B剩下的时间一定>=0。

模拟即可。

 1 #include <bits/stdc++.h>
 2 #define dbg(x) cout << #x " = " << x << "\n"
 3 #define mp make_pair
 4 #define y0 lkhklhhkukgasdxcsasdwre
 5 #define y1 ajsodihousejbkrjykuasyi
 6 #define rep(i , x , y) for(int (i)=(x);(i)<=(y);++i)
 7 #define per(i , y , x) for(int (i)=(y);(i)>=(x);--i)
 8 #define FORALLV(i , v) for(int i = 0; i < v . size(); ++i)
 9 /*********************
10   Template : LiM_817
11 *********************/
12 using namespace std;
13 typedef long long ll;
14 typedef unsigned long long ull;
15 typedef long double ld;
16 typedef pair <int , int> pii;
17 typedef pair <ll , ll> pll;
18 typedef vector <int> vi;
19 inline int read() {
20     int f = 1 , x = 0; char ch = getchar();
21     while(ch < '0' || ch > '9') {if(ch == '-') f = -1;ch = getchar();}
22     while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();};
23     return f * x;
24 }
25 template <typename T>
26 inline void print(T x) {
27     if(x < 0) putchar('-') , x = -x;
28     if(x >= 10) print(x / 10); putchar(x % 10 + 48);
29 }
30 
31 void p(vi &x) {
32     cout << x.size() << endl;
33     for(int arr : x) cout << arr << " ";
34     cout << endl;
35 }
36 int main() {
37     int a = read() , b = read();
38     
39     int s = 0;
40     int x = 0;
41     while(s + x <= a + b) {
42         s += x; x++;
43     }
44     vi va , vb;
45     x--;
46     
47     for(int i = x; i >= 1; i--) {
48         if(a >= i) {
49             a -= i;
50             va.push_back(i);
51         }
52         else if(b >= i) {
53             b -= i;
54             vb . push_back(i);
55         }
56     }
57     p(va) , p(vb);
58     return 0;
59 }

猜你喜欢

转载自www.cnblogs.com/LiM-817/p/10161808.html