이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Calm down.
// Think three times, code twice.
#include "bits/stdc++.h"
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7; // 998244353
const ll oo = 1e18;
vector<pll> a[2005];
vector<ll> x[2005];
ll s, n, dp[2005];
void to_nho_cau() {
cin >> s >> n;
forr(i, 1, n) {
ll v, w, k; cin >> v >> w >> k;
a[w].pb({v, k});
}
forr(i, 1, s) {
if(a[i].size()) {
sort(all(a[i]), greater<>());
int sl = 0; vector<ll> f;
forr(j, 0, a[i].size()-1) {
if(f.size() == s) break;
sl += a[i][j].nd;
while(f.size() < 2000 && a[i][j].nd) {
f.pb(a[i][j].st);
a[i][j].nd--;
}
}
x[i] = f;
}
}
// forr(i, 1, s) {
// cout << i << ": ";
// if(x[i].size())
// forr(j, 0, x[i].size()-1) cout << x[i][j] << " ";
// cout << "\n";
// }
memset(dp, -63, sizeof dp);
dp[0] = 0;
forr(i, 1, s) {
if(x[i].empty()) continue;
ford(j, s, 1) {
ll cur = 0, cur_val = 0;
forr(k, 0, x[i].size() - 1) {
cur += i;
cur_val += x[i][k];
if(cur > j) break;
dp[j] = max(dp[j], dp[j - cur] + cur_val);
// cout << i << " " << j << " " << cur << " " << cur_val << " " << dp[j] << "\n";
if(cur + i > j) break;
}
}
}
ll ans = 0;
forr(i, 1, s) ans = max(ans, dp[i]);
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef LOCAL
freopen(file".inp","r",stdin);
freopen(file".out","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--) to_nho_cau();
}
/*
1.self check:
2.long long
3.size of array
4.code for testing
5.initializing
6.modulo number
*/
/**
∧__∧
(`•ω• )づ__∧
(つ /( •ω•。)
しーJ (nnノ) pat pat
**/
/** /\_/\
* (= ._.)
* / >☕ \>💻
**/
/**
・*・ ∧,,∧ ∧_∧ ・*・
'. ( 。・ω・)(・ω・。 ) .'
'・ | つ♥と |.・'
*'***** '*
**/
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp:104:9: warning: "/*" within comment [-Wcomment]
104 | /** /\_/\
|
knapsack.cpp: In function 'void to_nho_cau()':
knapsack.cpp:4:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
| ^
knapsack.cpp:42:13: note: in expansion of macro 'forr'
42 | forr(j, 0, a[i].size()-1) {
| ^~~~
knapsack.cpp:43:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
43 | if(f.size() == s) break;
| ~~~~~~~~~^~~~
knapsack.cpp:4:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
| ^
knapsack.cpp:65:13: note: in expansion of macro 'forr'
65 | forr(k, 0, x[i].size() - 1) {
| ^~~~
# | 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... |