Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- typedef long long ll;
- int main() {
- ll n = 0;
- ll limit = 0;
- std::cin >> n >> limit;
- std::vector<ll> l(n);
- for (int i = 0; i < n; ++i) std::cin >> l[i];
- std::vector<ll> c(n);
- for (int i = 0; i < n; ++i) std::cin >> c[i];
- ll b = 0, e = 0; // Окно от кружка b до кружка e.
- ll part_b = 0; // Количество минут от старта кружка b[b] в окне.
- ll part_e = 0; // Количество минут от старта кружка l[e] в окне.
- // Собираем первое окно
- ll cap = 0;
- ll len = 0;
- for (; e < n; ++e) {
- if (len + l[e] <= limit) {
- len += l[e];
- cap += c[e] * l[e];
- } else {
- part_e = limit - len;
- cap += c[e] * part_e;
- break;
- }
- }
- ll max_cap = cap;
- while (e < n) {
- if (l[b] - part_b <= l[e] - part_e) {
- ll shift = l[b] - part_b;
- cap += shift * c[e] - shift * c[b];
- part_e += shift;
- if (part_e == l[e]) {++e; part_e = 0;}
- ++b;
- part_b = 0;
- } else {
- ll shift = l[e] - part_e;
- cap += shift * c[e] - shift * c[b];
- part_b += shift;
- ++e;
- part_e = 0;
- }
- max_cap = std::max(max_cap, cap);
- }
- std::cout << max_cap << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement