이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long int
#define ll long long
using namespace std;
const int N = 1e5 + 5;
int dp[N];
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<tuple<int,int,int>> v;
    for(int i=0;i<n;i++)
    {
        int c,f,cost;
        cin>>c>>f>>cost;
        v.push_back(make_tuple(f,-cost,c));
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int c,f,cost;
        cin>>c>>f>>cost;
        v.push_back(make_tuple(f,cost,c));
    }
    sort(v.begin(),v.end());
    const int inf = 1e15 + 5;
    for(int i=0;i<N;i++)
        dp[i] = -inf;
    dp[0] = 0;
    int ans = 0;
    for(int i=v.size()-1;i>=0;i--)
    {
        int c,f,cost;
        tie(f,cost,c) = v[i];
        if(cost < 0)       //buying
        {
            for(int j=N-1;j>=0;j--)
            {
                if(j + c < N)
                    dp[j + c] = max(dp[j + c],dp[j] + cost);
            }
        }
        else
        {
            for(int j=0;j<N;j++)
            {
                if(j - c >= 0)
                    dp[j - c] = max(dp[j - c],dp[j] + cost);
            }
        }
    }
    for(int i=0;i<N;i++)
        ans = max(ans,dp[i]);
    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... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |