Submission #761621

#TimeUsernameProblemLanguageResultExecution timeMemory
761621vgoofficialCloud Computing (CEOI18_clo)C++17
54 / 100
393 ms3928 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 n,m;
    cin >> n;
    vector<Order> shops;
    for(int i = 0; i < n; i++) {
        Order temp;
        cin >> temp.numCores >> temp.clockRate >> temp.money;
        shops.push_back(temp);
    }
    sort(shops.begin(), shops.end());
    vector<Order> customers;
    cin >> m;
    for(int i = 0; i < m; i++) {
        Order temp;
        cin >> temp.numCores >> temp.clockRate >> temp.money;
        customers.push_back(temp);
    }
    sort(customers.begin(), customers.end());
    ll maxProfit[50*(n+1)+1];
    for(int j = 0; j <= 50*(n+1); j++) {
        maxProfit[j]=-1e14;
    }
    int customerIndex = 0;
    while(shops[0].clockRate<customers[customerIndex].clockRate) customerIndex++;
    maxProfit[0]=0;
    for(int i = 1; i < n+1; i++) {
        ll tempMaxProfit[50*(n+1)+1];
        for(int j = 0; j <= 50*(n+1); j++) {
            tempMaxProfit[j]=-1e14;
        }
        for(int j = 0; j <= 50*(i-1); j++) {
            tempMaxProfit[j]=max(tempMaxProfit[j], maxProfit[j]); //dont buy from this shop
            tempMaxProfit[j+shops[i-1].numCores]=max(tempMaxProfit[j+shops[i-1].numCores], maxProfit[j]-shops[i-1].money); //buy from this shop
        }
        while(customerIndex<m) {
            if(i!=n&&customers[customerIndex].clockRate<=shops[i].clockRate) {
                break;
            }
            for(int j = customers[customerIndex].numCores; j <= 50*(n+1); j++) {
                tempMaxProfit[j-customers[customerIndex].numCores]=max(tempMaxProfit[j-customers[customerIndex].numCores], tempMaxProfit[j]+customers[customerIndex].money);
            }
            customerIndex++;
        }
        for(int j = 0; j <= 50 * (n+1); j++) {
            maxProfit[j]=tempMaxProfit[j];
        }
    }
    ll ans = 0;
    for(int i = 0; i <= 50 * (n+1); i++) {
        ans=max(ans, maxProfit[i]);
    }
    cout << ans << endl;
}
/*
3
4 2200 700
2 1800 10
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550
*/
#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...