Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int costs_count;
- cin >> costs_count;
- vector< vector< int > > costs_free_lunches_count(costs_count, vector< int >(costs_count + 1, 1e10));
- vector< int > costs(costs_count, 1e10);
- for (int i = 0; i < costs_count; ++i)
- {
- cin >> costs[i];
- }
- const int b = 100;
- bool is_even = true;
- int cost = costs.front();
- bool is_more_then_100 = (cost >= b);
- costs_free_lunches_count.front()[is_more_then_100] = cost;
- int last_cost = cost;
- for (int i = 1; i < costs_count; ++i)
- {
- int cost = costs[i];
- if (cost >= b) is_even = !is_even;
- for (int j = 0; j < costs_count; ++j)
- {
- int n_cost1 = costs_free_lunches_count[i - 1][j] + costs[i];
- int n_cost2 = costs_free_lunches_count[i - 1][j + 1];
- int n_cost = min(n_cost1, n_cost2);
- if (cost < b)
- {
- costs_free_lunches_count[i][j] = min(n_cost1, n_cost2);
- continue;
- } else {
- if (is_even && j + 1 < costs_count)
- j++;
- int n_cost1 = 1e10;
- if (j > 0)
- {
- n_cost1 = costs_free_lunches_count[i - 1][j - 1] + costs[i];
- }
- int n_cost2 = costs_free_lunches_count[i - 1][j + 1];
- int n_cost = min(n_cost1, n_cost2);
- costs_free_lunches_count[i][j] = n_cost;
- if (!is_even)
- {
- j++;
- }
- }
- }
- }
- cout << min(costs_free_lunches_count.back()[0], costs_free_lunches_count.back()[1]);
- return 0;
- }
- /*
- test1
- 7
- 5 6 5 7 5 3 6
- 18
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement