Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
1.6 kB
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> health(n), power(n);

  for (int i = 0; i < n; i++) {
    cin >> health[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> power[i];
  }
  vector<pair<int, int>> combined(n);
  for (int i = 0; i < n; i++) {
    combined[i] = {health[i], power[i]};
  }
  sort(
      combined.begin(), combined.end(),
      [](pair<int, int> &a, pair<int, int> &b) { return a.second < b.second; });

  for (int i = 0; i < n; ++i) {
    health[i] = combined[i].first;
    power[i] = combined[i].second;
  }
  int sum_health = 0;
  for (int i = 0; i < n; i++) {
    sum_health += health[i];
  }

  int attack = 1;
  int manster = 0;

  for (attack; attack < INT64_MAX; attack++) {
    for (int i = 0; i < n; i++) {
      if (health[i] >= k) {
        health[i] = health[i] - k;
        sum_health = sum_health - k;
        cout << "sum_health: " << sum_health << endl;
      } else {
        health[i] = 0;
        sum_health = sum_health - health[i];
        cout << "sum_health: " << sum_health << endl;
      }
      if (i == manster && health[manster] <= 0) {
        manster++;
      }
    }
    k = k - power[manster];
    if (sum_health>0 && k <= 0) {
      cout << "NO" << endl;
      return;
    }
    if(sum_health==0){
      cout << "YES" << endl;
      return;
    }
  }
}

signed main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}
Leave a Comment