제출 #1268346

#제출 시각아이디문제언어결과실행 시간메모리
1268346ducanh0811Cloud Computing (CEOI18_clo)C++20
100 / 100
171 ms1368 KiB
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define REV(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
using namespace std;

int n, m;
#define MAXN 2005
struct ks{
    int a, b, c;
};
struct user {
    int a, b, c;
};
vector<ks> kses;
vector<user> users;
const int INF = 1e15;
int f[MAXN * 100];

void solve(){
    cin >> n;
    FOR(i, 1, n){
        int a, b, c; cin >> a >> b >> c;
        kses.push_back({a, b, c});
    }
    cin >> m;
    FOR(i, 1, m){
        int a, b, c; cin >> a >> b >> c;
        users.push_back({a, b, c});
    }
    sort(kses.begin(), kses.end(), [](const ks &a, const ks &b){
        return a.b > b.b;
    });
    sort(users.begin(), users.end(), [](const user &a, const user &b){
        return a.b > b.b;
    });
    int ptr = 0;
    FOR(i, 0, 100000) f[i] = -INF;
    f[0] = 0;
    int full = 0;
    int res = 0;
    for (user &i : users){
        while (ptr < (int)kses.size() && kses[ptr].b >= i.b){
            int val = kses[ptr].c;
            int id = kses[ptr].a;
            full += id;
            for (int x = full; x >= id; --x){
                f[x] = max(f[x], f[x - id] - val);
            }
            ptr++;
        }
        int val = i.c;
        int id = i.a;
        for (int x = 0; x <= full - id; ++x){
            f[x] = max(f[x], f[x + id] + val);
        }
    }
    for (int i = 0; i <= full; ++i) res = max(res, f[i]);
    cout << res;
}

#define task "DATPHONG"
int32_t main(){
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    solve();
    return 0;
}

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

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