Submission #858963

#TimeUsernameProblemLanguageResultExecution timeMemory
858963hariaakas646Knapsack (NOI18_knapsack)C++17
100 / 100
91 ms67824 KiB
#include <bits/stdc++.h> using namespace std; #define scd(t) scanf("%d", &t) #define sclld(t) scanf("%lld", &t) #define forr(i, j, k) for (int i = j; i < k; i++) #define frange(i, j) forr(i, 0, j) #define all(cont) cont.begin(), cont.end() #define mp make_pair #define pb push_back #define f first #define s second typedef long long int lli; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<lli> vll; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef long double ld; void usaco() { freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin); // freopen("problem.out", "w", stdout); } int main() { // usaco(); int n, sz; scd(sz); scd(n); vector<vll> dp(sz+1, vll(sz+1)); vll tot(sz+1); vector<vector<pair<lli, lli>>> val(sz+1); frange(i, n) { lli a, b, c; sclld(a); sclld(b); sclld(c); tot[b] += c; val[b].pb(mp(a, c)); } forr(i, 1, sz+1) sort(all(val[i]), greater<>()); vector<vll> pref(sz+1, vll(sz+1)); forr(i, 1, sz+1) { int curr = 1; bool done = false; for(auto p : val[i]) { frange(j, p.s) { pref[i][curr] = pref[i][curr-1] + p.f; curr++; if(curr > sz) { done = true; break; } } if(done) break; } forr(j, curr, sz+1) { pref[i][j] = pref[i][j-1]; } } forr(i, 1, sz+1) { forr(j, 1, sz+1) { for(int k=0; j-i*k>=0; k++) { dp[i][j] = max(dp[i][j], dp[i-1][j-i*k] + pref[i][k]); } } } printf("%lld", *max_element(all(dp[sz]))); }

Compilation message (stderr)

knapsack.cpp: In function 'void usaco()':
knapsack.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
knapsack.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(sz);
      |     ^~~
knapsack.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
knapsack.cpp:38:5: note: in expansion of macro 'scd'
   38 |     scd(n);
      |     ^~~
knapsack.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
knapsack.cpp:48:9: note: in expansion of macro 'sclld'
   48 |         sclld(a);
      |         ^~~~~
knapsack.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
knapsack.cpp:49:9: note: in expansion of macro 'sclld'
   49 |         sclld(b);
      |         ^~~~~
knapsack.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
knapsack.cpp:50:9: note: in expansion of macro 'sclld'
   50 |         sclld(c);
      |         ^~~~~
#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...