제출 #1336792

#제출 시각아이디문제언어결과실행 시간메모리
1336792hauserlCloud Computing (CEOI18_clo)C++20
36 / 100
241 ms1092 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int INF = 1e18;

struct C{
    int c;
    int f;
    int v;
    int t; // 1 for offer, -1 for order
    bool operator<(const auto& o) const {
        if (f != o.f) return f > o.f;
        return t > o.t;
    }
};

int main() {
    vector<C> computers;
    int n; scanf("%d",&n);
    int maxCores = 5;
    for (int i = 0; i < n; i++) {
        int c,f,v; scanf("%d %d %d",&c,&f,&v);
        computers.push_back(C{c,f,v, 1});
        maxCores+=c;
    }

    int m; scanf("%d",&m);
    for (int i = 0; i < m; i++) {
        int c,f,v; scanf("%d %d %d",&c,&f,&v);
        computers.push_back(C{c,f,v,-1});
    }

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

    vector<ll> dp(maxCores+1, -INF);
    dp[0] = 0;

    for (const auto& computer : computers) {
        if (computer.t == 1) {
            for (int j = maxCores; j >= computer.c; j--) {
                if (dp[j-computer.c] != -INF) dp[j] = max(dp[j], dp[j-computer.c] - computer.v);
            }
        } else {
            for (int j = 0; j <= maxCores-computer.c; j++) {
                if (dp[j+computer.c] != -INF) dp[j] = max(dp[j], dp[j+computer.c]+computer.v);
            }
        }
    }

    ll ma = 0;
    for (int i = 0; i < maxCores+1; i++) {
        ma = max(ma, dp[i]);
    }

    printf("%lld", ma);
    return 0;
}

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

clo.cpp:5:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    5 | const int INF = 1e18;
      |                 ^~~~
clo.cpp: In function 'int main()':
clo.cpp:20:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     int n; scanf("%d",&n);
      |            ~~~~~^~~~~~~~~
clo.cpp:23:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         int c,f,v; scanf("%d %d %d",&c,&f,&v);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
clo.cpp:28:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     int m; scanf("%d",&m);
      |            ~~~~~^~~~~~~~~
clo.cpp:30:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         int c,f,v; scanf("%d %d %d",&c,&f,&v);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...