제출 #1096567

#제출 시각아이디문제언어결과실행 시간메모리
1096567dostsKnapsack (NOI18_knapsack)C++17
73 / 100
1078 ms3932 KiB
//SİGUSMUS SEFEROĞLU #include <bits/stdc++.h> #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") using namespace std; #define int long long #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 conv(int x) { if (x <= -inf/2) return -1; return x; } 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]; vi sack(w+1),sack2(w+1,-inf); sack2[0] = 0; for (int i=1;i<=n;i++) { vector<deque<int>> dqs(c[i]); for (int j = 0;j<=w;j++) { int bin = j%c[i]; deque<int>& dq = dqs[bin]; while (!dq.empty() && k[i] < (j-dq.front())/c[i]) { dq.pop_front(); //cout<<j<<" i pissed my pants\n"; } while (!dq.empty() && (j-dq.back())/c[i]*v[i]+sack2[dq.back()] <= sack2[j]) { dq.pop_back(); //cout<<j<<" what???\n"; } dq.push_back(j); sack[j] = (j-dq.front())/c[i]*v[i]+sack2[dq.front()]; } swap(sack,sack2); } cout << *max_element(sack2.begin(),sack2.end()) << 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...