이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define Fast ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
template<class T> using ordered_set = tree<T, null_type , less<T> ,rb_tree_tag , tree_order_statistics_node_update> ;
typedef long long ll;
const int N=5e2+3,M=2e7+3,LG=__lg(N)+2,MOD=998244353;
void solve() {
int n,s,V,W,K;
cin>>s>>n;
vector<vector<pair<int,int>>>bestW(s+1);
for (int i = 0; i <n ; ++i) {
cin >> V >> W >> K;
bestW[W].emplace_back(V,K);
}
vector<int>v,w,dp(s+1,INT_MIN);
for (int i = 1; i <=s ; ++i) {
sort(all(bestW[i]));
for (int j = 0; j <s&&!bestW[i].empty() ; j+=i) {
v.push_back(bestW[i].back().first);
w.push_back(i);
if(!--bestW[i].back().second)
bestW[i].pop_back();
}
}
n=v.size();
dp[0]=0;
for (int i = 0; i <n ; ++i) {
for (int j = s; j >=w[i] ; --j) {
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
cout<<*max_element(all(dp))<<'\n';
}
int main() {
Fast;
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) {
// cout<<"Case #"<<i<<": ";
solve();
}
}
# | 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... |