이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 998244353;
int add(int x, int y){
return ((x + y) % MOD + MOD) % MOD;
}
int mul(int x, int y){
return x * 1ll * y % MOD;
}
int binpow(int x, int y){
int z = 1;
while(y){
if(y % 2 == 1) z = mul(z, x);
x = mul(x, x);
y /= 2;
}
return z;
}
int inv(int x){
return binpow(x, MOD - 2);
}
int divide(int x, int y){
return mul(x, inv(y));
}
int main(){
int s, n;
cin>>s>>n;
map<int, vector<pair<int, int>>>mp;
for(int i = 1;i<=n;i++){
int v, w, k;
cin>>v>>w>>k;
mp[w].push_back({v, k});
}
for(auto &x : mp){
sort((x.second).begin(), (x.second).end(), greater<pair<int, int>>());
}
vector<vector<long long>>dp(int(mp.size()), vector<long long>(s+1, 0));
auto it = mp.begin();
long long res = 0;
for(int i = 0;i<int(mp.size());i++){
for(int use = 0; use <= s; use++){
int sum = 0;
int val = 0;
dp[i][use] = (i-1 >= 0?dp[i-1][use]:0);
for(auto &x : it->second){
val += x.first;
sum += it->first;
if(sum > use)break;
dp[i][use] = max(dp[i][use], val + (i-1 >= 0?dp[i-1][use - sum]:0));
}
res = max(res, dp[i][use]);
}
it++;
}
cout<<res<<"\n";
}
# | 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... |