# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059955 | kachim2 | Cloud Computing (CEOI18_clo) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<array<int, 3>> comp(n);
for(int i = 0; i < n; i++){
cin >> comp[i][0] >> comp[i][1] >> comp[i][2];
}
std::sort(comp.begin(), comp.end());
int m;
cin >> m;
vector<array<int, 3>> ord(m);
for(int i = 0; i < m; i++){
cin >> ord[i][0] >> ord[i][1] >> ord[i][2];
}
std::sort(ord.begin(), ord.end());
vector<pair<int, int>> a;
vector<int> money;
vector<bool> taken(n);
int profit = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(comp[i][1] >= ord[j][1]){
a.push_back(i, ord[j][1]);
money.push_back(ord[j][2]);
ord[j][1]=INT_MAX;
taken[i]=1;
}
}
}
while(!a.empty()){
auto x = a.back();
a.pop_back();
taken[x.first] = 0;
int mini = x.first;
for(int i = 0; i < n; i++){
if(comp[i][1] >= x.second && comp[mini][2]>comp[i][2]){
mini = i;
}
}
taken[mini] = 1;
profit+=max(0, money.back()-comp[mini][2]);
}
cout << profit << '\n';
return 0;
}