#include <bits/stdc++.h>
using ll = long long;
using std::vector;
using std::array;
using std::tuple;
using std::pair;
template <class F> struct fixed : private F {
explicit fixed(F&& f) : F(std::forward<F>(f)) {}
template <class... Args> decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
template <class T>
constexpr T infty = std::numeric_limits<T>::max() / 2;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int M;
ll T;
std::cin >> M >> T;
assert(M <= 100);
ll zero;
vector<ll> low(M), high(M);
for (int i = M - 1; i >= 0; --i) {
std::cin >> low[i];
}
std::cin >> zero;
for (int i = 0; i < M; ++i) {
std::cin >> high[i];
}
const auto calc = [&](const vector<ll>& vec) {
vector<int> dp = {0};
for (int w = 1; w <= M; ++w) {
const int K = vec[w - 1];
vector<int> next((int)dp.size() + K * w, -infty<int>);
for (int r = 0; r < w; ++r) {
std::deque<pair<int, int>> deq;
for (int q = 0;; ++q) {
const int i = r + q * w;
if (i >= (int)next.size()) {
break;
}
if (i < (int)dp.size()) {
const int add = dp[i] - q;
while (!deq.empty() and deq.back().first < add) {
deq.pop_back();
}
deq.emplace_back(add, q);
}
while (!deq.empty() and deq.front().second + K < q) {
deq.pop_front();
}
if (!deq.empty()) {
next[i] = deq.back().first + q;
}
}
}
dp = std::move(next);
}
return dp;
};
const auto minus = calc(low);
const auto plus = calc(high);
int ans = -infty<int>;
for (int i = 0; i < (int)minus.size(); ++i) {
const int j = T + i;
if (0 <= j and j < (int)plus.size()) {
ans = std::max(ans, minus[i] + (int)zero + plus[j]);
}
}
if (ans < 0) {
std::cout << "impossible\n";
} else {
std::cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
12 ms |
760 KB |
Output is correct |
6 |
Correct |
12 ms |
812 KB |
Output is correct |
7 |
Correct |
9 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
796 KB |
Output is correct |
9 |
Correct |
26 ms |
1184 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
12 ms |
760 KB |
Output is correct |
6 |
Correct |
12 ms |
812 KB |
Output is correct |
7 |
Correct |
9 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
796 KB |
Output is correct |
9 |
Correct |
26 ms |
1184 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
12 ms |
760 KB |
Output is correct |
6 |
Correct |
12 ms |
812 KB |
Output is correct |
7 |
Correct |
9 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
796 KB |
Output is correct |
9 |
Correct |
26 ms |
1184 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
12 ms |
760 KB |
Output is correct |
6 |
Correct |
12 ms |
812 KB |
Output is correct |
7 |
Correct |
9 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
796 KB |
Output is correct |
9 |
Correct |
26 ms |
1184 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
12 ms |
760 KB |
Output is correct |
6 |
Correct |
12 ms |
812 KB |
Output is correct |
7 |
Correct |
9 ms |
468 KB |
Output is correct |
8 |
Correct |
15 ms |
796 KB |
Output is correct |
9 |
Correct |
26 ms |
1184 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |