fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4.  
  5. void solve() {
  6. ll n , k;
  7. cin >> n >> k;
  8. vector<ll> v(n + 1);
  9. for (int i = 1 ; i <= n ; i++)
  10. cin >> v[i];
  11. vector<vector<ll>> dp(n + 1, vector<ll> (45));
  12.  
  13. for (int i = 1 ; i <= n ; i++) {
  14. dp[i][0] = dp[i-1][0] - k + v[i];
  15. for (int j = 1 ; j < 40 ; j++) {
  16. dp[i][j] = max(dp[i-1][j] - k + (v[i] / (1ll << j)) ,
  17. dp[i-1][j-1] + (v[i] / (1ll << j)));
  18. }
  19. }
  20.  
  21. cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
  22. }
  23.  
  24. int32_t main() {
  25. int t = 1;
  26. cin >> t;
  27. while(t--) {
  28. solve();
  29. }
  30. }
Runtime error #stdin #stdout #stderr 0.01s 5460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc