CF1394A Boboniu Chats with Du
注:把大于m的ai自身看作没有价值,即价值为0
补:图中方块长度为4是错的,应该是3.即20覆盖0 0 0 18覆盖 1 2 2 17覆盖2 4 5
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 #include <vector> 8 #include <cstring> 9 #include <functional> 10 #include <map> 11 #define LL long long 12 #define lson(rt) (rt << 1) 13 #define rson(rt) (rt << 1 | 1) 14 using namespace std; 15 16 const int N = 1e6 + 10; 17 18 void fun() 19 { 20 21 int sum = 0; 22 int x; 23 while(cin >> x) sum += x; 24 cout << "sum = " << sum << endl; 25 } 26 27 void solve () 28 { 29 //fun(); 30 int n, d, m; 31 scanf("%d%d%d", &n, &d, &m); 32 d++; 33 vector<LL > tmp, v, add; 34 for(int i = 0; i < n; ++i) { 35 long long x; 36 scanf("%lld", &x); 37 tmp.push_back(x); 38 } 39 sort(tmp.begin(), tmp.end()); 40 for(auto x : tmp) cout << x << " "; 41 cout << endl; 42 long long sum = tmp[n - 1]; 43 for(int i = 0; i < n - 1; ++i) { 44 if(tmp[i] > m) { 45 v.push_back(0); 46 add.push_back(tmp[i]); 47 } else v.push_back(tmp[i]); 48 } 49 sort(v.begin(), v.end()); 50 sort(add.begin(), add.end()); 51 reverse(add.begin(), add.end());/* 52 for(auto x : v) cout << x << " "; 53 cout << endl; 54 for(auto x : add) cout << x << " "; 55 cout << endl;*/ 56 int _add = add.size(); 57 int _v = v.size(); 58 int l = 0; 59 for(int i = 0; i < _add; ++i) { 60 // l += d; 61 if(l + d > _v) break; 62 long long x = 0; 63 for(int j = l; j < l + d; ++j) x += v[j]; 64 if(x < add[i]) { 65 sum += add[i]; 66 l += d; 67 } else break; 68 } 69 for(int i = l; i < _v; ++i) sum += v[i]; 70 // printf("value = %d\n", sum); 71 printf("%lld\n", sum); 72 } 73 74 int main () 75 { 76 // ios::sync_with_stdio(false); 77 // cin.tie(0); cout.tie(0); 78 79 solve(); 80 81 return 0; 82 }
1