제출 #815547

#제출 시각아이디문제언어결과실행 시간메모리
815547winthemcut3Knapsack (NOI18_knapsack)C++14
100 / 100
49 ms3700 KiB
#include <bits/stdc++.h> #define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ll long long #define PB push_back #define ALL(v) (v).begin(), (v).end() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define fi first #define se second #define BIT(x, i) (((x) >> (i)) & 1) using namespace std; /** END OF TEMPLATE **/ const int mxN = 1e5 + 5; struct item { int v, k; bool operator < (const item &t1) { return v > t1.v; } }; int n, s; ll dp[2005]; vector<item> a[2005]; int main() { FastIO; //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); cin >> s >> n; FOR(i, 1, n) { int v, w, k; cin >> v >> w >> k; a[w].PB({v, k}); } FOR(i, 1, s) { sort(ALL(a[i])); int id = 0, lim = s/i; FOR(j, 0, lim) { if(id >= a[i].size()) break; FORD(k, s, i) dp[k] = max(dp[k], dp[k-i] + 1ll*a[i][id].v); a[i][id].k--; if(!a[i][id].k) id++; } } ll res = 0; FOR(i, 1, s) res = max(res, dp[i]); cout << res; return 0; } /* */

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<item>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if(id >= a[i].size()) break;
      |                ~~~^~~~~~~~~~~~~~
#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...