Advertisement
HabKaffee

Untitled

Oct 31st, 2020
142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main() {
  9.     int level, k = 0;
  10.     while (k == 0 || level == 0)
  11.         cin >> level >> k;
  12.     vector<int> monsters_on_level(level), time_level_start(level), time_level_finish(level);
  13.     for (size_t i = 0; i < level; ++i)
  14.         cin >> time_level_start[i] >> time_level_finish[i] >> monsters_on_level[i];
  15.     vector<int> counter_bullet(level, INT_MAX);
  16.     counter_bullet[0] = 0;
  17.  
  18.     int res = INT_MAX;
  19.     for (size_t i = 0; i < level; ++i) {
  20.         int left = k;
  21.         int spend_bullets_level = counter_bullet[i];
  22.         for (size_t j = i; j < level; ++j) {
  23.             int count_reloads = max(0, (((monsters_on_level[j] - left) + k - 1) / k));
  24.             if (count_reloads > time_level_finish[j] - time_level_start[j]) {
  25.                 break;
  26.             }
  27.             int new_left_bullet_magazine = left + k * count_reloads - monsters_on_level[j];
  28.             if (spend_bullets_level != INT_MAX) {
  29.                 spend_bullets_level += monsters_on_level[j];
  30.             }
  31.             if (j + 1 < level) {
  32.                 if (time_level_start[j] + count_reloads < time_level_start[j + 1])
  33.                     counter_bullet[j + 1] = min(counter_bullet[j + 1], spend_bullets_level == INT_MAX ? INT_MAX : spend_bullets_level + new_left_bullet_magazine);
  34.             }
  35.             else res = min(res, spend_bullets_level);
  36.             left = new_left_bullet_magazine;
  37.         }
  38.     }
  39.     res == INT_MAX ? cout << -1 : cout << res;
  40.     return 0;
  41. }
  42.  
Advertisement
RAW Paste Data Copied
Advertisement