제출 #876421

#제출 시각아이디문제언어결과실행 시간메모리
876421arkash707Knapsack (NOI18_knapsack)C++17
0 / 100
0 ms348 KiB
#include<iostream> #include<vector> using namespace std; int s, n; //good: {price, weight, quantity} int a[100001][3]; long long solve() { long long dp[s+1]; for (int i=0; i<=s; i++) dp[i] = -1; dp[0] = 0; long long res = 0; for (int i=0; i<n; i++) { int p = a[i][0], w = a[i][1], q = a[i][2]; for (int j=s; j>=0; j--) { if (dp[j] == -1) continue; for (int k=0; k<=q; k++) { if (1L*j+w*k > s) continue; dp[j+w*k] = max(dp[j+w*k], dp[j] + p*k); res = max(res, dp[j+w*k]); } } } return res; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif cin >> s >> n; for (int i=0; i<n; i++) { for (int j=0; j<3; j++) { cin >> a[i][j]; } } cout << solve() << "\n"; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen("input.txt","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen("output.txt","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...