Submission #585795

#TimeUsernameProblemLanguageResultExecution timeMemory
585795imtiyazrasool92Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms672 KiB
#include<stdio.h> int min(int A, int B) { return A > B ? B : A; } int max(int A, int B) { return A < B ? B : A; } int S, N; int dp[2001][100000]; int A[100000][3]; int dfs(int index, int weight) { if (weight == 0) return 0; if (index >= N) return 0; if (dp[weight][index] == -1) { dp[weight][index] = 0; for (int i = 0; i <= min(weight / A[index][1], A[index][2]); i++) { if (weight - (i * A[index][1]) >= 0) dp[weight][index] = max(dp[weight][index], dfs(index + 1, weight - (i * A[index][1])) + A[index][0] * i); else break; } } return dp[weight][index]; } int main() { scanf("%d%d", &S, &N); for (int i = 0; i < N; i++) { scanf("%d%d%d", &A[i][0], &A[i][1], &A[i][2]); if (A[i][1] > S) { N--; i--; } else if (A[i][1] == 0) { N--; i--; } } for (int i = 0; i < N; i++) for (int s = 0; s <= S; s++) dp[i][s] = -1; printf("%d", dfs(0, S)); }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d%d", &S, &N);
      |     ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d%d%d", &A[i][0], &A[i][1], &A[i][2]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...