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>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MOD = 1e9 + 7;
const int MAXN = 1e6+1;
struct specs{
int core, speed, value;
inline bool operator<(specs b) const{
return speed > b.speed;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<specs> comp(n);
bool c1 = 1, s1 = 1, v1 = 1;
int corecount = 0;
for(int i = 0; i < n; i++)
cin >> comp[i].core >> comp[i].speed >> comp[i].value, corecount+=comp[i].core,c1 = c1&&(comp[i].core==1), s1 = s1&&(comp[i].speed==1),v1 = v1&&(comp[i].value==1);
int m;
cin >> m;
vector<specs> order(m);
for(int i = 0; i < m; i++)
cin >> order[i].core >> order[i].speed >> order[i].value, c1 = c1&&(order[i].core==1), s1 = s1&&(order[i].speed==1),v1 = v1&&(order[i].value==1);
sort(comp.begin(),comp.end());
sort(order.begin(),order.end());
multiset<int> available;
multiset<int> accepted;
ll cost = 0;
int ptr = 0;
for(int i = 0; i < m; i++){
while(ptr < n && comp[ptr].speed >= order[i].speed){
available.insert(comp[ptr].value);
ptr++;
}
if(available.empty() || *available.begin() >= order[i].value){
if(!accepted.empty() && *accepted.begin() > order[i].value){
accepted.erase(accepted.begin());
accepted.insert(order[i].value);
}
}else {
cost+=*available.begin();
available.erase(available.begin());
accepted.insert(order[i].value);
}
}
ll resp = 0;
for(int i : accepted)
resp+=i;
cout << resp - cost << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |