Submission #1123899

#TimeUsernameProblemLanguageResultExecution timeMemory
1123899wrttKnapsack (NOI18_knapsack)C++20
17 / 100
2 ms1864 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define pb emplace_back #define mx(a, b) ((a) > (b) ? (a) : (b)) #define mn(a, b) ((a) < (b) ? (a) : (b)) #define graph(n) vector<int> g[(n)+1]; constexpr int mod = 998244353; constexpr int inf = 1e18; void frx(std::string name) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } /* template <typename T, size_t N> ostream &operator<<(ostream &os, const T (&arr)[N]) { os << "["; for(size_t i = 0; i < N; ++i) { if(i>0) { os << ", "; } os<<arr[i]; } return os << "]"; } */ void solve() { int s,n; cin>>s>>n; int v[n], w[n], k[n]; for(int i = 0; i < n; ++i) { cin>>v[i]>>w[i]>>k[i]; } int dp[n+1][s+1]; memset(dp,0,sizeof(dp)); for(int i = 1; i<=n; ++i) { for(int j = 0; j<=s; ++j) { dp[i][j] = dp[i-1][j]; if(j>=w[i-1]) { dp[i][j] = mx(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1]); } } } cout<<dp[n][s]<<"\n"; } signed main() { std::ios_base::sync_with_stdio(false); //std::cin.tie(nullptr); //frx("piggyback"); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); auto start = std::chrono::high_resolution_clock::now(); #endif int t = 1; //cin >> t; int curr = 1; while (t--) { //cout<<"Case "<<curr<<"\n"; ++curr; solve(); } #ifdef LOCAL auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = end - start; std::cout << elapsed.count() << " seconds\n"; #endif return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void frx(std::string)':
knapsack.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   freopen((name + ".out").c_str(), "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...