D - Yet Another Monster Killing Problem

Topic connection:

https://codeforces.com/contest/1257/problem/D

Subject to the effect:

n-monster, m hero, each monster has some ability value, the ability of each hero a certain value and a certain value of endurance. Endurance is worth the meaning can kill the largest number of monster every day. When the capacity is greater than the capacity value of the hero monster value, the hero can kill the monster, and then asked to kill

The minimum time required for all the monsters, if not kill all the monsters, the output 1;

Ideas: a main understanding of a mx mx array [i] meaning in the case of endurance value of i, the maximum capacity hero.

#include<bits/stdc++.h>
using namespace std;
const int N=2E5+7;
int arr[N];
int mx[N];
int p[N],abi[N];
void solve(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) mx[i]=0;
    for(int i=1;i<=n;i++)   scanf("%d",&arr[i]);
    int m;
    Scanf ( " % D " , & m);
     for ( int I = . 1 ; I <= m; I ++ ) { 
        Scanf ( " % D% D " , & ABI [I], & P [I]); 
        MX [P [i]] = max (MX [P [i]], ABI [i]); 
    } 
    // day to kill a hero i will be able to kill the i-1 th.
    // i.e. MX [i] is the maximum capacity is equal to the endurance hero greater than i. 
    for ( int I = N- . 1 ; I> = . 1 ; i--) MX [I] = max (MX [I], MX [I + . 1 ]);
     int Day = 0 , J = . 1 ;
     BOOL In Flag =to false ;
     for ( int I = . 1 ; I <= n-;) { 
        Day ++ ; 
        In Flag = to false ;
         int MAXN = 0 ;
         int tmp = I;
         // one day kill the maximum number may find these monster maximum capacity, then find the maximum ability to kill a monster hero in x mx array. 
        the while ( . 1 ) { 
            MAXN = max (ARR [I], MAXN);
             IF (MAXN> MX [I-tmp + . 1 ]) BREAK ; 
            I ++ ; 
            In Flag = to true ;
        }
        if(!flag) break;
    }
    if(!flag) day=-1;
    printf("%d\n",day);
    return ;
}

int main(){
    cin.tie(0);
    int t;
    scanf("%d",&t);
    while(t--) solve();
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Accepting/p/11911605.html