Advertisement
tepyotin2

Ciel and Duel

May 27th, 2025
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, m;
  6. vector<int> atk;
  7. vector<int> def;
  8. int ciel[101];
  9. int ans;
  10.  
  11. int main(){
  12.     //freopen("cielandduel.in", "r", stdin);
  13.    
  14.     cin >> n >> m;
  15.     for(int i=0; i<n; i++){
  16.         string a;
  17.         int b;
  18.         cin >> a >> b;
  19.         if(a == "ATK"){
  20.             atk.push_back(b);
  21.         }else if(a == "DEF"){
  22.             def.push_back(b);
  23.         }
  24.     }
  25.     for(int i=0; i<m; i++){
  26.         cin >> ciel[i];
  27.     }
  28.     sort(atk.begin(), atk.end());
  29.     sort(def.begin(), def.end());
  30.     sort(ciel, ciel+m);
  31.     int aidx = 0;
  32.     int didx = 0;
  33.     int val = 0;
  34.     //For each card ciel has, first check Jiro's defense cards and then attack cards.
  35.     //If the card isn't large enough to be used for defense cards, then use it for attack cards.
  36.     //Since it is in sorted order if a card doesn't work there isn't a possibility it could work for any other of
  37.     //Jiro's defense or attack cards. If it doesn't work for any of Jiro's cards, 'then just assume the card
  38.     //can be used for direct attack used directly without any defense cards or attack cards in the way from
  39.     //Jiro's side. Final answer will only be valid if all of Jiro's defense and attack cards have been used.
  40.     for(int i=0; i<m; i++){
  41.         if(didx<def.size() && ciel[i]>def[didx]){
  42.             didx++;
  43.             continue;
  44.         }
  45.         if(aidx<atk.size() && ciel[i]>=atk[aidx]){
  46.             val+=ciel[i]-atk[aidx];
  47.             aidx++;
  48.             continue;
  49.         }
  50.         val+=ciel[i];
  51.     }
  52.     if(didx == def.size() && aidx == atk.size()){
  53.         ans = max(ans, val);
  54.     }
  55.     aidx = 0;
  56.     val = 0;
  57.     //For the case where only Jiro's attack cards are hit with Ciel's attack cards, if one of ciel's cards
  58.     //doesn't work on a attack card, no more values can be added because there are no more of Ciel's
  59.     //attack cards that would work on a single one of Jiro's attack cards which is valid because of the
  60.     //sorted order of Ciel's and Jiro's cards. Need to keep index of Jiro's attack cards because if the
  61.     //cases are done we should just end because we cannot add any more of Ciel's card values to the
  62.     //value of total points.
  63.     for(int i=m-1; i>=0 && aidx<atk.size(); i--){
  64.         //cout << ciel[i] << '\n';
  65.         if(ciel[i]>atk[aidx]){
  66.             val+=ciel[i]-atk[aidx];
  67.             aidx++;
  68.         }else{
  69.             break;
  70.         }
  71.     }
  72.     ans = max(ans, val);
  73.     cout << ans << '\n';
  74.    
  75.     return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement