이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
using namespace std;
const int N = 1e5 + 5;
const int S = 1e5 + 5;
const ll oo = 1e17;
template <typename T1, typename T2> bool maxi(T1 &a, T2 &b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 &b){if (a > b){a = b; return 1;} return 0;}
int n, s;
vector <int> v, w, k;
bool ar;
vector <vector<ll>> f;
ll ans;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> s >> n;
v.assign(n + 1, 0);
w.assign(n + 1, 0);
k.assign(n + 1, 0);
for (int i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
}
f.assign(2, vector <ll> (s + 2, 0));
for (int i = 1; i <= n; i++){
ar ^= 1;
for (int j = 0; j <= s; j++){
f[ar][j] = f[ar ^ 1][j];
int l = 1, r = k[i];
while (l <= r){
int m = (l + r) >> 1;
if (w[i] * m > j){
r = m - 1;
continue;
}
ll tmp = f[ar ^ 1][j - w[i] * m] + 1ll * v[i] * m;
if (maxi(f[ar][j], tmp)){
l = m + 1;
} else r = m - 1;
}
}
}
for (int j = 0; j <= s; j++)
maxi(ans, f[ar][j]);
cout << ans;
}
# | 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... |