제출 #761702

#제출 시각아이디문제언어결과실행 시간메모리
761702vgoofficialCloud Computing (CEOI18_clo)C++14
100 / 100
603 ms2132 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Order {
    ll numCores, clockRate, money;
    bool operator<(Order other) {
        if(other.clockRate>clockRate) {
            return false;
        }
        return true;
    }
};
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    int total=0;
    int n,m;
    cin >> n;
    vector<Order> shops2;
    vector<Order> shops;
    for(int i = 0; i < n; i++) {
        Order temp;
        cin >> temp.numCores >> temp.clockRate >> temp.money;
        shops.push_back(temp);
        temp.money=-temp.money;
        shops2.push_back(temp);
        total+=temp.numCores;
    }
    //sort(shops.begin(), shops.end());
    cin >> m;
    vector<Order> customers;
    for(int i = 0; i < m; i++) {
        Order temp;
        cin >> temp.numCores >> temp.clockRate >> temp.money;
        customers.push_back(temp);
        temp.numCores=-temp.numCores;
        shops2.push_back(temp);
    }
    //sort(customers.begin(), customers.end());
    sort(shops2.begin(), shops2.end(), [](const Order &a, const Order &b) -> bool{
        return a.clockRate != b.clockRate ? a.clockRate > b.clockRate : a.money < b.money;
    });
    ll maxProfit[total+1];
    for(int j = 0; j <= total; j++) {
        maxProfit[j]=-1e14;
    }
    maxProfit[0]=0;
    for(int i = 0; i < shops2.size(); i++) {
        ll tempMaxProfit[total+1];
        for(int j = 0; j <= total; j++) {
            tempMaxProfit[j]=maxProfit[j];
        }
        for(int j = 0; j <= total; j++) {
            int prev = j - shops2[i].numCores;
            if(prev>=0&&prev<=total) {
                tempMaxProfit[j]=max(tempMaxProfit[j], maxProfit[prev]+shops2[i].money);
            }
        }
        for(int j = 0; j <= total; j++) {
            maxProfit[j]=tempMaxProfit[j];
        }
    }
    ll ans = 0;
    for(int i = 0; i <= total; i++) {
        ans=max(ans, maxProfit[i]);
    }
    

                    /*
    ll maxxProfit[50*(n+1)+1];
    for(int j = 0; j <= 50*(n+1); j++) {
        maxxProfit[j]=-1e14;
    }
    int customerIndex = 0;
    //while(customerIndex<m&&shops[0].clockRate<customers[customerIndex].clockRate) customerIndex++;
    maxxProfit[0]=0;

    for(int i = 1; i < n+1; i++) {
        ll tempmaxxProfit[50*(n+1)+1];
        for(int j = 0; j <= 50*(n+1); j++) {
            tempmaxxProfit[j]=-1e14;
        }

        for(int j = 0; j <= 50*(i-1); j++) {
            tempmaxxProfit[j]=max(tempmaxxProfit[j], maxxProfit[j]); //dont buy from this shop
            tempmaxxProfit[j+shops[i-1].numCores]=max(tempmaxxProfit[j+shops[i-1].numCores], maxxProfit[j]-shops[i-1].money); //buy from this shop
        }

        while(customerIndex<m) {
            if(i!=n) {
                if(customers[customerIndex].clockRate<=shops[i].clockRate) {
                    break;
                }
            }
            for(int j = customers[customerIndex].numCores; j <= 50*(n+1); j++) {
                tempmaxxProfit[j-customers[customerIndex].numCores]=max(tempmaxxProfit[j-customers[customerIndex].numCores], maxxProfit[j]+customers[customerIndex].money);
            }
            customerIndex++;
        }

        for(int j = 0; j <= 50 * (n+1); j++) {
            maxxProfit[j]=tempmaxxProfit[j];
        }
    }
        */
    cout << ans << endl;
}
/*
3
4 2200 700
2 1800 10
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550
*/

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

clo.cpp: In function 'int main()':
clo.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Order>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0; i < shops2.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~
#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...