#include<bits/stdc++.h> using namespace std; using LL=long long; #define FOR(i,l,r)for(int i=(l);i<=(r);++i) #define REP(i,n)FOR(i,0,(n)-1) #define ssize(x)int(x.size()) #ifdef DEBUG auto operator<<(auto&o,auto x)->decltype(x.end(),o); auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";} auto&operator<<(auto&o,tuple<auto,auto,auto>t){return o<<"("<<get<0>(t)<<", "<<get<1>(t)<<", "<<get<2>(t)<<")";} auto&operator<<(auto&o,tuple<auto,auto,auto,auto>t){return o<<"("<<get<0>(t)<<", "<<get<1>(t)<<", "<<get<2>(t)<<", "<<get<3>(t)<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";} #define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X) #else #define debug(...){} #endif const int INF = 1e9; void solve() { int n, m; cin >> n >> m; vector<int> a(n); REP(i, n) cin >> a[i]; vector<int> last_accepted(n, -INF), proposition(n, -INF); auto print = [&]() { REP(i, n) { if (last_accepted[i] < 0) last_accepted[i] = -1; if (i) cout << ' '; cout << last_accepted[i]; } cout << '\n'; }; if (n == 1) { last_accepted[0] = m; print(); return; } last_accepted[n - 2] = m; last_accepted[n - 1] = 0; const LL factor = 1e5; const LL helper = 6e4; vector<LL> options(n - 1); for (int i = n - 3; i >= 0; --i) { const int others_needed = (n - i - 1) / 2; FOR(j, i + 1, n - 1) { proposition[j] = 0; options[j - i - 1] = max(last_accepted[j] + a[j], 0) * factor - j + helper; } nth_element(options.begin(), options.begin() + (others_needed - 1), options.begin() + (n - i - 1)); int used = 0; REP(j, others_needed) { const auto xd = options[j]; const int value = int(xd / factor); const int id = int(value * factor - xd + helper); used += value; proposition[id] = value; } if (used <= m) { proposition[i] = m - used; swap(last_accepted, proposition); } } print(); } int main() { cin.tie(0)->sync_with_stdio(0); solve(); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include<bits/stdc++.h> using namespace std; using LL=long long; #define FOR(i,l,r)for(int i=(l);i<=(r);++i) #define REP(i,n)FOR(i,0,(n)-1) #define ssize(x)int(x.size()) #ifdef DEBUG auto operator<<(auto&o,auto x)->decltype(x.end(),o); auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";} auto&operator<<(auto&o,tuple<auto,auto,auto>t){return o<<"("<<get<0>(t)<<", "<<get<1>(t)<<", "<<get<2>(t)<<")";} auto&operator<<(auto&o,tuple<auto,auto,auto,auto>t){return o<<"("<<get<0>(t)<<", "<<get<1>(t)<<", "<<get<2>(t)<<", "<<get<3>(t)<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";} #define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X) #else #define debug(...){} #endif const int INF = 1e9; void solve() { int n, m; cin >> n >> m; vector<int> a(n); REP(i, n) cin >> a[i]; vector<int> last_accepted(n, -INF), proposition(n, -INF); auto print = [&]() { REP(i, n) { if (last_accepted[i] < 0) last_accepted[i] = -1; if (i) cout << ' '; cout << last_accepted[i]; } cout << '\n'; }; if (n == 1) { last_accepted[0] = m; print(); return; } last_accepted[n - 2] = m; last_accepted[n - 1] = 0; const LL factor = 1e5; const LL helper = 6e4; vector<LL> options(n - 1); for (int i = n - 3; i >= 0; --i) { const int others_needed = (n - i - 1) / 2; FOR(j, i + 1, n - 1) { proposition[j] = 0; options[j - i - 1] = max(last_accepted[j] + a[j], 0) * factor - j + helper; } nth_element(options.begin(), options.begin() + (others_needed - 1), options.begin() + (n - i - 1)); int used = 0; REP(j, others_needed) { const auto xd = options[j]; const int value = int(xd / factor); const int id = int(value * factor - xd + helper); used += value; proposition[id] = value; } if (used <= m) { proposition[i] = m - used; swap(last_accepted, proposition); } } print(); } int main() { cin.tie(0)->sync_with_stdio(0); solve(); } |