Submission #648121

#TimeUsernameProblemLanguageResultExecution timeMemory
648121LextyleKnapsack (NOI18_knapsack)C++17
100 / 100
167 ms236708 KiB
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma warning(disable : 6031) #define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w+", stdout); #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long using namespace std; /* */ ll dp[15519][2001]; pair<int, pair<int, int>> a[100000]; pair<int, int> b[15518]; bool pred(pair<int, pair<int, int>> a1, pair<int, pair<int, int>> a2) { if (a1.first < a2.first) return 1; else if (a1.first == a2.first) return a1.second.first > a2.second.first; return 0; } int main() { //USACO; fastIO; int s, n; cin >> s >> n; for (int i = 0; i < n; i++) cin >> a[i].second.first >> a[i].first >> a[i].second.second; sort(a, a + n, pred); int cnt = 0, ind = 0; for (int i = 0; i < n; i++) { if (i == 0 || a[i].first != a[i - 1].first) cnt = 0; for (int j = 0; cnt < s / a[i].first && j < a[i].second.second; j++) { b[ind++] = { a[i].first, a[i].second.first }; cnt++; } } for (int i = 1; i <= ind; i++) { for (int j = b[i - 1].first; j <= s; j++) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1].first] + b[i - 1].second); } } cout << dp[ind][s] << "\n"; }

Compilation message (stderr)

knapsack.cpp:2: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    2 | #pragma warning(disable : 4996)
      | 
knapsack.cpp:3: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    3 | #pragma warning(disable : 6031)
      |
#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...