Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m;
- vector<int> atk;
- vector<int> def;
- int ciel[101];
- int ans;
- int main(){
- //freopen("cielandduel.in", "r", stdin);
- cin >> n >> m;
- for(int i=0; i<n; i++){
- string a;
- int b;
- cin >> a >> b;
- if(a == "ATK"){
- atk.push_back(b);
- }else if(a == "DEF"){
- def.push_back(b);
- }
- }
- for(int i=0; i<m; i++){
- cin >> ciel[i];
- }
- sort(atk.begin(), atk.end());
- sort(def.begin(), def.end());
- sort(ciel, ciel+m);
- int aidx = 0;
- int didx = 0;
- int val = 0;
- //For each card ciel has, first check Jiro's defense cards and then attack cards.
- //If the card isn't large enough to be used for defense cards, then use it for attack cards.
- //Since it is in sorted order if a card doesn't work there isn't a possibility it could work for any other of
- //Jiro's defense or attack cards. If it doesn't work for any of Jiro's cards, 'then just assume the card
- //can be used for direct attack used directly without any defense cards or attack cards in the way from
- //Jiro's side. Final answer will only be valid if all of Jiro's defense and attack cards have been used.
- for(int i=0; i<m; i++){
- if(didx<def.size() && ciel[i]>def[didx]){
- didx++;
- continue;
- }
- if(aidx<atk.size() && ciel[i]>=atk[aidx]){
- val+=ciel[i]-atk[aidx];
- aidx++;
- continue;
- }
- val+=ciel[i];
- }
- if(didx == def.size() && aidx == atk.size()){
- ans = max(ans, val);
- }
- aidx = 0;
- val = 0;
- //For the case where only Jiro's attack cards are hit with Ciel's attack cards, if one of ciel's cards
- //doesn't work on a attack card, no more values can be added because there are no more of Ciel's
- //attack cards that would work on a single one of Jiro's attack cards which is valid because of the
- //sorted order of Ciel's and Jiro's cards. Need to keep index of Jiro's attack cards because if the
- //cases are done we should just end because we cannot add any more of Ciel's card values to the
- //value of total points.
- for(int i=m-1; i>=0 && aidx<atk.size(); i--){
- //cout << ciel[i] << '\n';
- if(ciel[i]>atk[aidx]){
- val+=ciel[i]-atk[aidx];
- aidx++;
- }else{
- break;
- }
- }
- ans = max(ans, val);
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement