이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define f first
#define s second
typedef pair<int,int> pii;
typedef tuple<int, int, int> iii;
int mod = (int)1e9 + 7;
int lt(int l, int r, function<bool(int x)> f)
{
l--;
while(l < r)
{
int m = l + (r - l + 1) / 2;
if(f(m)) r = m;
else l = m + 1;
}
return l;
}
int pw(int a, int b)
{
int ans = 1;
while(b > 0)
{
if(b & 1) ans *= a;
ans %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ans;
}
int inverse(int x)
{
return pw(x, mod - 2);
}
void solve()
{
int s, n; cin >> s >> n;
int dp[s + 1] = {0};
bool pro[s + 1] = {false};
pro[0] = true;
map<int, int> mp;
for(int x = 1; x < 2001; x++) mp[x] = s/x;
vector<pii> choose;
vector<iii> a;
for(int x = 0; x < n; x++)
{
int v, w, k; cin >> v >> w >> k;
a.push_back({v, w, k});
}
sort(a.begin(), a.end());
for(iii t : a)
{
int v = get<0>(t);
int w = get<1>(t);
int k = get<2>(t);
if(mp[w] >= k)
{
for(int x = 0; x < k; x++) choose.push_back({v, w});
mp[w] -= k;
}
else
{
for(int x = 0; x < mp[w]; x++) choose.push_back({v, w});
mp[w] = 0;
}
}
int mx = 0;
for(pii p : choose)
{
//cout << p.f << " " << p.s << "\n";
for(int x = s; x >= 0; x--)
{
if(x - p.s >= 0)
{
if(pro[x - p.s])
{
pro[x] = true;
dp[x] = max(dp[x], dp[x - p.s] + p.f);
mx = max(mx, dp[x]);
}
}
}
}
cout << mx;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
//freopen("wormsort.in", "r", stdin);
//freopen("wormsort.out", "w", stdout);
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
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... |