QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#330229 | #8057. Best Carry Player 4 | ucup-team987# | WA | 47ms | 3532kb | C++23 | 3.2kb | 2024-02-17 13:51:02 | 2024-02-17 13:51:03 |
Judging History
answer
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
namespace {
void solve() {
int m;
scan(m);
std::vector<i64> a(m);
scan(a);
std::vector<i64> b(m);
scan(b);
{
const i64 sum_a = std::accumulate(a.begin(), a.end(), i64{0});
const i64 sum_b = std::accumulate(b.begin(), b.end(), i64{0});
if (sum_a < sum_b) {
a[0] += sum_b - sum_a;
} else if (sum_b < sum_a) {
b[0] += sum_a - sum_b;
}
}
i64 ans = 0;
i64 cur = 0;
bool ok = false;
int count = 0;
for (const int i : rep(m)) {
const bool rest = 0 < cur;
cur += b[m - i - 1];
const i64 t = std::min(a[i], cur);
if (0 < t) {
if (rest) {
ok = true;
}
++count;
}
ans += t;
cur -= t;
}
if (!ok) {
if (count == 1) {
ans = 0;
} else {
--ans;
}
}
print(ans);
}
} // namespace
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout << std::setprecision(DBL_DECIMAL_DIG);
int t;
scan(t);
while (t--) {
solve();
}
}
#else // __INCLUDE_LEVEL__
#include <bits/stdc++.h>
template <class T, class U = T>
bool chmin(T& x, U&& y) {
return y < x && (x = std::forward<U>(y), true);
}
template <class T, class U = T>
bool chmax(T& x, U&& y) {
return x < y && (x = std::forward<U>(y), true);
}
template <std::signed_integral T = int>
T inf() {
T ret;
std::memset(&ret, 0x3f, sizeof(ret));
return ret;
}
template <std::floating_point T>
T inf() {
return std::numeric_limits<T>::infinity();
}
template <class T>
concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T>
concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;
namespace std {
istream& operator>>(istream& is, Range auto&& r) {
for (auto&& e : r) {
is >> e;
}
return is;
}
istream& operator>>(istream& is, Tuple auto&& t) {
return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}
ostream& operator<<(ostream& os, Range auto&& r) {
for (string_view sep = ""; auto&& e : r) {
os << exchange(sep, " ") << e;
}
return os;
}
ostream& operator<<(ostream& os, Tuple auto&& t) {
const auto f = [&](auto&... xs) -> ostream& {
[[maybe_unused]] string_view sep = "";
((os << exchange(sep, " ") << xs), ...);
return os;
};
return apply(f, t);
}
} // namespace std
void scan(auto&&... xs) { std::cin >> std::tie(xs...); }
void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; }
template <class F>
class fix {
public:
explicit fix(F f) : f_(std::move(f)) {}
decltype(auto) operator()(auto&&... xs) const {
return f_(std::ref(*this), std::forward<decltype(xs)>(xs)...);
}
private:
F f_;
};
inline auto rep(int l, int r) { return std::views::iota(std::min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
namespace ranges = std::ranges;
namespace views = std::views;
using i64 = std::int64_t;
#endif // __INCLUDE_LEVEL__
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
5 2 1 2 3 4 3 1 0 1 0 1 0 4 1 0 0 1 1 1 1 1 5 123456 114514 1919810 233333 234567 20050815 998244353 0 0 0 10 5 3 5 3 2 4 2 4 1 5 9 9 8 2 4 4 3 5 3 0
output:
5 1 2 467900 29
result:
ok 5 number(s): "5 1 2 467900 29"
Test #2:
score: -100
Wrong Answer
time: 47ms
memory: 3532kb
input:
100000 5 0 1 1 1 1 0 0 1 0 0 5 0 0 0 0 0 1 1 1 0 0 5 0 0 2 1 1 0 2 1 0 1 5 0 0 0 0 0 1 2 1 0 0 5 0 1 0 1 1 0 0 1 1 1 5 2 0 0 0 1 1 0 0 0 3 5 2 0 0 1 1 0 2 1 1 1 5 0 0 0 0 2 0 0 0 0 1 5 0 0 0 0 0 0 1 1 0 0 5 4 0 0 0 0 0 0 0 1 0 5 0 0 0 0 1 2 1 1 0 0 5 0 2 3 0 0 0 0 0 1 0 5 1 1 1 0 1 1 0 1 0 1 5 0 0 0...
output:
1 -1 4 -1 3 3 3 2 -1 -1 1 0 2 0 3 0 0 -1 -1 0 0 0 4 0 4 1 -1 2 3 3 1 5 0 -1 2 0 0 1 1 -1 0 3 5 3 2 2 0 -1 0 2 2 2 -1 3 0 2 1 1 0 1 -1 4 0 0 2 2 -1 3 3 -1 2 -1 1 -1 0 1 1 2 0 3 4 -1 2 5 -1 1 1 0 0 -1 2 1 3 -1 1 0 4 3 3 0 2 2 0 1 3 1 1 -1 0 -1 1 -1 3 2 2 -1 1 0 1 0 1 -1 0 2 4 1 2 3 2 2 2 -1 1 -1 0 2 3...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'