이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ld eps = 1e-8;
// for matching the kactl notes
#define sz(x) ((int)x.size())
#define rep(i,a,b) for (int i = (int)(a); i < (int)(b); ++i)
#define all(a) (a).begin(), (a).end()
// #define constexpr(...) (__VA_ARGS__)
// DEBUGING TEMPLETE ////////////////////////////////////////////////////////////////////////{{{
#define db(val) "["#val" = "<<(val)<<"] "
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef LOCAL_DEBUG
# define clog cerr << flush << string(__db_level * 2, ' ')
# define DB() debug_block CONCAT(dbbl, __LINE__)
int __db_level = 0;
struct debug_block {
debug_block() { clog << "{" << endl; ++__db_level; }
~debug_block() { --__db_level; clog << "}" << endl; }
};
#else
# define clog if (0) cerr
# define DB(...)
#endif
template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
if constexpr(i == tuple_size<T>::value) return out << ")";
else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template<class ...U> ostream& operator<<(ostream& out, const tuple<U...>& tup) {
return print_tuple_utils<0, tuple<U...>>(out, tup);
}
template<class Con, class = decltype(begin(declval<Con>()))>
typename enable_if<!is_same<Con, string>::value, ostream&>::type
operator<<(ostream& out, const Con& container) {
out << "{";
for (auto it = container.begin(); it != container.end(); ++it)
out << (it == container.begin() ? "" : ", ") << *it;
return out << "}";
}
// ACTUAL SOLUTION START HERE ////////////////////////////////////////////////////////////////}}}
const ll inf = 1e16;
int main() {
#ifdef LOCAL
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
freopen(".log", "w", stderr);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int s, n;
cin >> s >> n;
vector<ll> dp(s + 1, -inf);
dp[0] = 0;
while (n--) {
ll v;
int w, k;
cin >> v >> w >> k;
vector<ll> new_dp = dp;
rep(i, 0, s + 1) dp[i] -= v * (i / w);
rep(rem, 0, w) {
deque<int> qu;
for (int i = rem; i <= s; i += w) {
while (qu.size() and (i - qu[0]) / w > k) qu.pop_front();
while (qu.size() and (dp[qu.back()] <= dp[i])) qu.pop_back();
qu.push_back(i);
new_dp[i] = max(new_dp[i], dp[qu[0]] + v * (i / w));
}
}
swap(dp, new_dp);
}
cout << *max_element(all(dp));
return 0;
}
// vim: foldmethod=marker
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |