제출 #1279631

#제출 시각아이디문제언어결과실행 시간메모리
1279631swishy123Cloud Computing (CEOI18_clo)C++20
100 / 100
232 ms1316 KiB
#include <bits/stdc++.h>

#define ll long long
#define pi pair<int, int>
#define x first
#define y second

const ll inf = 1e18;
const int def = 1e5+1;
using namespace std;

ll dp[def];
void solve(){
    for (int i = 1; i < def; i++)
        dp[i] = -inf;

    vector<tuple<int, int, int>> B;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++){
        int c, f, v;
        cin >> c >> f >> v;

        B.push_back({f, c, -v});
    }
    
    int m;
    cin >> m;

    for (int i = 0; i < m; i++){
        int c, f, v;
        cin >> c >> f >> v;

        B.push_back({f, -c, v});
    }

    sort(B.begin(), B.end());

    for (int i = B.size() - 1; i >= 0; i--){
        auto [f, c, v] = B[i];
        if (c > 0){
            for (int i = def - 1; i >= c; i--)
                dp[i] = max(dp[i], dp[i - c] + v);
        }
        else{
            c = -c;
            for (int i = 0; i < def - c; i++)
                dp[i] = max(dp[i], dp[i + c] + v);
        }
    }
    ll res = 0;
    for (int i = 0; i < def; i++)
        res = max(res, dp[i]);
    cout << res;
}   

/*
1 2 3 a 1 2 3 b

*/

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if (ifstream("input.txt").good()){
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
    }

    int t;
    t = 1;
    
    while (t--){
        solve();
    }
}

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

clo.cpp: In function 'int main()':
clo.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("output.txt", "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...