이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//SİGUSMUS SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
#define int int64_t
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e18;
const int N = 2e5+50,Q = 2e5+50;
int alloc[1000000];
struct MagicianArray {
int ptr = 0;
int sz = 0;
inline int front() {
return alloc[ptr];
}
inline int back() {
return alloc[ptr+sz-1];
}
inline void push_back(int x) {
alloc[ptr+sz] = x;
sz++;
}
inline void pop_back() {
sz--;
}
inline void pop_front() {
ptr++;
sz--;
}
};
void solve() {
int n,w;
cin >> w >> n;
int v[n+1],c[n+1],k[n+1];
for (int i=1;i<=n;i++) cin >> v[i] >> c[i] >> k[i];
int*sack=new int[w+1],*sack2=new int[w+1];
for (int i=0;i<=w+1;i++) sack2[i] = -inf;
sack2[0] = 0;
MagicianArray dq;
for (int i=1;i<=n;i++) {
for (int jj = 0;jj<c[i];jj++) {
dq.sz = dq.ptr = 0;
for (int j = jj;j<=w;j+=c[i]) {
while (dq.sz && k[i] < (j-dq.front())/c[i]) {
dq.pop_front();
}
while (dq.sz && (j-dq.back())/c[i]*v[i]+sack2[dq.back()] <= sack2[j]) {
dq.pop_back();
}
dq.push_back(j);
sack[j] = (j-dq.front())/c[i]*v[i]+sack2[dq.front()];
}
}
swap(sack,sack2);
}
cout << *max_element(sack2,sack2+w+1) << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |