Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #define c_boost std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr)
- using namespace std;
- using LL = long long;
- using PLL = pair <LL, LL>;
- const LL mod = 10e9 + 7;
- // @author: Danielto1404
- void solve() {
- int n, m;
- cin >> n;
- vector <LL> enemy;
- vector <PLL> heroes;
- LL max_enemy = 0;
- LL max_hero = 0;
- enemy.resize(n);
- for (LL& power: enemy) {
- cin >> power;
- max_enemy = max(max_enemy, power);
- }
- cin >> m;
- heroes.resize(m);
- for (PLL& hero: heroes) {
- cin >> hero.first >> hero.second;
- max_hero = max(max_hero, hero.first);
- }
- if (max_hero < max_enemy) {
- cout << -1;
- return;
- }
- sort(heroes.begin(), heroes.end());
- int idx = 0;
- int days = 0;
- while (idx < n) {
- LL enemyPower = enemy[idx];
- int curDays = INT32_MAX;
- int start = 0;
- for (int i = 0; i < n; ++i)
- if (heroes[i].first >= enemyPower) {
- start = i;
- break;
- }
- int enemyIdx = idx;
- for (int i = start; i < m; ++i) {
- LL heroPower = heroes[i].first;
- LL heroStamina = heroes[i].second;
- while (enemyIdx < n && enemy[enemyIdx] <= heroPower && enemyIdx - idx < heroStamina) {
- enemyIdx++;
- }
- curDays = min(curDays, enemyIdx - idx);
- }
- days++;
- idx += curDays;
- }
- cout << days << '\n';
- }
- int main() {
- c_boost;
- int t;
- cin >> t;
- while (t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement