Submission #710803

#TimeUsernameProblemLanguageResultExecution timeMemory
710803vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
200 ms35436 KiB
/* بسم الله الرحمن الرحيم وَاتَّقُوا يَوْمًا تُرْجَعُونَ فِيهِ إِلَى اللَّهِ ۖ ثُمَّ تُوَفَّىٰ كُلُّ نَفْسٍ مَّا كَسَبَتْ وَهُمْ لَا يُظْلَمُونَ In The name if allah And fear a Day when you will be returned to Allah Then every soul will be compensated for what it earned and they will not be treated unjustly. */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update> void init() { cin.tie(nullptr); std::istream::sync_with_stdio(false); cout.tie(nullptr); std::ostream::sync_with_stdio(false); } const long long mod = 1e9 + 7; vector<pair<int, int>> vec[2001]; long long dp[2001][2001]; long long n, s; long long solve(int i, int w) { if (w == 0) return w; if (i > w) return 0; long long &ret = dp[i][w]; if (~ret) return ret; ret = solve(i + 1, w); bool is = true; long long ans = 0, tot = 0; for (int j = 0; j < vec[i].size(); ++j) { for (int k = 1; k <= vec[i][j].second; ++k) { ans += vec[i][j].first; tot += i; if (w >= tot) ret = max(ret, solve(i + 1, w - tot) + ans); else { is = false; break; } } if (!is) break; } return ret; } int main() { init(); cin >> s >> n; memset(dp, -1, sizeof dp); int w, v, k; for (int i = 0; i < n; ++i) { cin >> v >> w >> k; vec[w].emplace_back(v, k); } for (int i = 1; i <= s; ++i) sort(vec[i].begin(), vec[i].end(), greater<pair<int, int >>()); cout << solve(1, s); }

Compilation message (stderr)

knapsack.cpp: In function 'long long int solve(int, int)':
knapsack.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int j = 0; j < vec[i].size(); ++j) {
      |                     ~~^~~~~~~~~~~~~~~
#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...