fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "exchange"
  33.  
  34. const int MOD = 1e9 + 7;
  35. const int inf = 1e9 + 27092008;
  36. const ll INF = 1e18 + 27092008;
  37. const int N = 2e5 + 5;
  38. int n, p, c[N], dp[N];
  39. vector<int> trace[N];
  40.  
  41. void init(void) {
  42. cin >> n >> p;
  43. FOR(i, 1, n) cin >> c[i];
  44. sort(c + 1, c + n + 1);
  45. }
  46.  
  47. void process(void) {
  48. memset(dp, -0x3f, sizeof dp);
  49. c[0] = -1;
  50. dp[0] = 0;
  51. int sum = 0;
  52.  
  53. FOR(i, 1, n) {
  54. sum += c[i];
  55. FORR(j, sum, c[i])
  56. if (maximize(dp[j], dp[j - c[i]] + (c[i] != c[i - 1])))
  57. trace[j].pb(i);
  58. }
  59. int res = 0, jres = 0;
  60. FORR(j, sum - p, 0) if (maximize(res, dp[j]))
  61. jres = j;
  62. cout << res << ' ' << sum - jres << '\n';
  63. vector<bool> keep(n+1, false);
  64. while(jres) {
  65. while(!trace[jres].empty() && keep[trace[jres].back()]) trace[jres].pop_back();
  66. int i = trace[jres].back();
  67. keep[i] = true;
  68. jres -= c[i];
  69. }
  70.  
  71. vector<int> ans;
  72. FOR(i, 1, n) if (!keep[i] && c[i] > 0)
  73. ans.pb(c[i]);
  74. sort(all(ans));
  75. for(int x : ans) cout << x << ' ';
  76. }
  77.  
  78. int main() {
  79. ios_base::sync_with_stdio(0);
  80. cin.tie(0); cout.tie(0);
  81. if (fopen(task".inp", "r")) {
  82. freopen(task".inp", "r", stdin);
  83. freopen(task".out", "w", stdout);
  84. }
  85. int tc = 1;
  86. // cin >> tc;
  87. while(tc--) {
  88. init();
  89. process();
  90. }
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0.01s 9060KB
stdin
Standard input is empty
stdout
0 0