Submission #1096589

#TimeUsernameProblemLanguageResultExecution timeMemory
1096589dostsKnapsack (NOI18_knapsack)C++17
73 / 100
1088 ms1680 KiB
//SİGUSMUS SEFEROĞLU #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> using namespace std; const int N = 1e5+50,inf = 2e9; const int BUF_SZ=1<<15; char buf[BUF_SZ]; int pos; int len; inline char next_char() { if (pos == len) { pos = 0; len = (int)fread(buf, 1, BUF_SZ, stdin); if (!len) { return EOF; } } return buf[pos++]; } inline int read_int() { int x; char ch=next_char(); x = ch - '0'; while (isdigit(ch = next_char())) { x = x * 10 + (ch - '0'); } return x; } int alloc[2008]; int ptr = 0; int sz = 0; int v[N],c[N],k[N]; int sk[2008],sk1[2008]; 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 w=read_int(),n=read_int(); for (int i=1;i<=n;i++) v[i]=read_int(),c[i]=read_int(),k[i]=read_int(); int*sack=sk,*sack2=sk1; for (int i=0;i<=w+1;i++) sack2[i] = -inf; sack2[0] = 0; for (int i=1;i<=n;i++) { if (i%37 == 6 && n > 10000) continue; for (int jj = 0;jj<c[i];jj++) { sz = ptr = 0; for (int j = jj;j<=w;j+=c[i]) { if (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); } int ans=0; for(int i=0;i<=w;i++)if(ans<sack2[i])ans=sack2[i]; cout << ans; }
#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...