제출 #1096582

#제출 시각아이디문제언어결과실행 시간메모리
1096582dostsKnapsack (NOI18_knapsack)C++17
73 / 100
1065 ms2640 KiB
//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 = 2e9; const int N = 2e5+50,Q = 2e5+50; int alloc[3000]; int ptr = 0; int sz = 0; void solve() { int n,w; cin >> w >> n; vi 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; for (int i=1;i<=n;i++) { for (int jj = 0;jj<c[i];jj++) { sz = ptr = 0; for (int j = jj;j<=w;j+=c[i]) { while (sz && k[i] < (j-alloc[ptr])/c[i]) { sz--; ptr++; } while (sz && (j-alloc[ptr+sz-1])/c[i]*v[i]+sack2[alloc[sz+ptr-1]] <= sack2[j]) { sz--; } alloc[sz+ptr] = j; sz++; sack[j] = (j-alloc[ptr])/c[i]*v[i]+sack2[alloc[ptr]]; } } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...