제출 #312203

#제출 시각아이디문제언어결과실행 시간메모리
312203BeanZCloud Computing (CEOI18_clo)C++14
100 / 100
2950 ms2296 KiB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl '\n'
const int N = 2e3 + 5;
const int lim = 100;
ll dp[N][lim + 5];
struct viet{
    ll c, f, v;
    bool operator <(const viet& o) const{
        return f > o.f;
    }
}a[N], b[N];
ll c[N], v[N], f[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i].c >> a[i].f >> a[i].v;
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= lim; j++){
            dp[i][j] = -1e18;
        }
    }
    dp[0][0] = 0;
    sort(a + 1, a + n + 1);
    ll ans = 0;
    ll m;
    cin >> m;
    for (int i = 1; i <= m; i++){
        cin >> b[i].c >> b[i].f >> b[i].v;
    }
    sort(b + 1, b + m + 1);
    /*
    for (int j = 1; j <= n; j++){
        /*
        for (int k = 0; k <= 50; k++){
            if (k >= a[j].c) dp[j][k] = max(dp[j][k], dp[j - 1][k - a[j].c] - a[j].v);
            //cout << dp[j][k] << " " << j << " " << k << endl;
        }
        for (int k = 50; k >= 0; k--){
            for (int i = 1; i <= m; i++){
                if (k >= a[j].c) dp[j][k] = max(dp[j][k], dp[j - 1][k - a[j].c] - a[j].v);
                if ((k + c[i]) <= 50 && f[i] <= a[j].f) dp[j][k] = max(dp[j][k], dp[j][k + c[i]] + v[i]);
                ans = max(ans, dp[j][k]);

            }
        }
    }*/
    for (int i = 1; i <= n; i++) dp[i][a[i].c] = -a[i].v;
    for (int i = 1; i <= m; i++){
    //cout << dp[1][0] << endl;
        for (int j = 1; j <= n; j++){
            for (int k = 0; k <= lim; k++){
                dp[j][k] = max(dp[j][k], dp[j - 1][k]);
                if (k >= a[j].c) {
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - a[j].c] - a[j].v);
                }
            }
            for (int k = lim - 1; k >= 0; k--) dp[j][k] = max(dp[j][k], dp[j][k + 1]);
        }
        for (int j = n; j >= 1; j--){
            //cout << dp[1][1] << endl;
            for (int k = 0; k <= lim; k++){
                //for (int i = 1; i <= m; i++){
                //for (int k = 0; k <= 50; k++){
                    if ((k + b[i].c) <= lim && b[i].f <= a[j].f) dp[j][k] = max(dp[j][k], dp[j][k + b[i].c] + b[i].v);
                    ans = max(ans, dp[j][k]);
                    //cout << dp[j][k] << " " << j << " " << k << endl;
               //}
            }
        }
        //cout << dp[3][80] << endl;
    }
    cout << ans;
}
/*
3
6 4 3
45 5 3
35 4 1
3
43 3 5
31 4 4
34 3 3
*/

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp:45:9: warning: "/*" within comment [-Wcomment]
   45 |         /*
      |          
clo.cpp: In function 'int main()':
clo.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   21 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   22 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...