제출 #416584

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
4165842021-06-02 16:23:37penguinhackerKnapsack (NOI18_knapsack)C++14
100 / 100
69 ms3648 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxS=2000;
int n, s, dp[mxS+1];
vector<ar<int, 2>> v[mxS+1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> n;
for (int i=0; i<n; ++i) {
int a, b, c;
cin >> a >> b >> c;
v[b].push_back({a, c});
}
for (int i=1; i<=s; ++i) {
if (v[i].empty())
continue;
sort(v[i].rbegin(), v[i].rend());
int x=i;
for (ar<int, 2> a : v[i]) {
if (x>s)
break;
for (int j=0; j<a[1]&&x<=s; ++j, x+=i)
for (int k=s; k>=i; --k)
dp[k]=max(dp[k], dp[k-i]+a[0]);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...