이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define debug(x) cerr << #x << " = " << (x) << ' '
#define bug(x) cerr << (x) << ' '
#define endl cerr << '\n'
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()
#define lowbit(x) (x)&-(x)
#define pb emplace_back
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
//#define TEST
const int N = 1e5+5;
ll wei[N], val[N], num[N], dp[2005], sum[N];
vector<ll> v[2005], com;
int main(void)
{ IO
ll n, i, T;
cin >> T >> n;
for (i=1; i <= n; ++i)
cin >> val[i] >> wei[i] >> num[i], v[wei[i]].pb(i);
for (i=1; i <= 2000; ++i)
{
if (v[i].empty()) continue;
com.clear();
for (ll x : v[i]) com.pb(val[x]);
sort(all(com)); com.resize(unique(all(com))-com.begin());
for (ll j=0; j < SZ(com); ++j) sum[j] = 0;
for (ll x : v[i])
{
auto it = lower_bound(all(com), val[x]) - com.begin();
sum[it] += num[x];
}
ll tot = 0;
for (ll t=SZ(com)-1; t >= 0; --t)
{
tot += sum[t];
if (tot > T/i) sum[t] -= tot - T/i;
for (ll j=1; sum[t] > 0; j <<= 1)
{
ll tmp = min(j, sum[t]);
sum[t] -= tmp;
for (ll k=T; k >= tmp*i; --k)
{
dp[k] = max(dp[k], dp[k-tmp*i] + com[t]*tmp);
}
}
if (tot > T/i) break;
}
}
cout << dp[T] << '\n';
return 0;
}
# | 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... |