| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 788056 | Andrey | Knapsack (NOI18_knapsack) | C++14 | 52 ms | 5068 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long,long long>> haha[2001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,a,b,c,s,y,ans = 0;
cin >> s >> n;
for(long long i = 0; i < n; i++) {
cin >> a >> b >> c;
haha[b].push_back({a,c});
}
vector<pair<long long,long long>> bruh(0);
for(long long i = 1; i <= s; i++) {
sort(haha[i].begin(),haha[i].end());
reverse(haha[i].begin(),haha[i].end());
c = s/i;
y = 0;
while(c > 0 && !haha[i].empty()) {
if(haha[i][y].second == 0) {
y++;
if(y >= haha[i].size()) {
break;
}
}
bruh.push_back({i,haha[i][y].first});
haha[i][y] = {haha[i][y].first,haha[i][y].second-1};
c--;
}
}
vector<long long> dp(s+1);
for(long long i = 0; i < bruh.size(); i++) {
a = bruh[i].first;
b = bruh[i].second;
for(long long j = s; j >= a; j--) {
dp[j] = max(dp[j],dp[j-a]+b);
ans = max(ans,dp[j]);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
