<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 貪心

      D. Yet Another Monster Killing Problem

      You play a computer game. In this game, you lead a party of ?? heroes, and you have to clear a dungeon with ?? monsters. Each monster is characterized by its power ????. Each hero is characterized by his power ???? and endurance ????.

      The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.

      When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated ?? monsters, the hero fights with the monster ??+1). When the hero fights the monster, there are two possible outcomes:

      if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
      otherwise, the monster is defeated.
      After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the ??-th hero cannot defeat more than ???? monsters during each day), or if all monsters are defeated — otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.

      Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.

      Input

      The first line contains one integer ?? (1≤??≤105) — the number of test cases. Then the test cases follow.

      The first line of each test case contains one integer ?? (1≤??≤2?105) — the number of monsters in the dungeon.

      The second line contains ?? integers ??1, ??2, ..., ???? (1≤????≤109), where ???? is the power of the ??-th monster.

      The third line contains one integer ?? (1≤??≤2?105) — the number of heroes in your party.

      Then ?? lines follow, each describing a hero. Each line contains two integers ???? and ???? (1≤????≤109, 1≤????≤??) — the power and the endurance of the ??-th hero.

      It is guaranteed that the sum of ??+?? over all test cases does not exceed 2?105.

      Output

      For each test case print one integer — the minimum number of days you have to spend to defeat all of the monsters (or ?1 if it is impossible).

      Example

      input
      2
      6
      2 3 11 14 1 8
      2
      3 2
      100 1
      5
      3 5 100 2 3
      2
      30 5
      90 1
      output
      5
      -1

      題意

      有n個怪獸 ,每個怪獸都有能力值a[i]。

      然后現在你有m個英雄,每個英雄也有能力值p[i],每個英雄還有一個s[i],表示這個英雄一天最多能消滅多少個怪獸

      現在你必須一個接一個的消滅怪獸,不能改變順序,然后問你最少多少天,能夠消滅所有的怪獸

      題解

      我們維護一個數組d[i],表示至少堅持i天的英雄的能力最大是多少。

      然后我們對于每一天,進行貪心選擇最多的即可。我們優先看堅持一天的,能否大于最大的,然后看堅持兩天的,這樣一直看下去即可。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      const int maxn = 2e5+7;
      int power[maxn],en[maxn],mons[maxn],hero[maxn];
      void solve(){
      	int n,mxm=-1,mxh=-1,m,ans=0;
      	scanf("%d",&n);
      	for(int i=0;i<n;i++){
      		scanf("%d",&mons[i]);
      		mxm=max(mxm,mons[i]);
      		hero[i]=0;
      	}
      	scanf("%d",&m);
      	for(int i=0;i<m;i++){
      		scanf("%d%d",&power[i],&en[i]);
      		mxh=max(mxh,power[i]);
      		hero[en[i]-1]=max(hero[en[i]-1],power[i]);
      	}
      	if(mxh<mxm){
      		puts("-1");
      		return;
      	}
      	for(int i=n-2;i>=0;i--){
      		hero[i]=max(hero[i],hero[i+1]);
      	}
      	int day=0,cur=-1,cons=-1;
      	while(day<n){
      		cur=max(cur,mons[day]);
      		cons++;
      		if(hero[cons]<cur){
      			ans++;
      			cons=0;
      			cur=mons[day];
      		}
      		day++;
      	}
      	ans++;
      	cout<<ans<<endl;
      }
      int main(){
      	int t;scanf("%d",&t);
      	while(t--){
      		solve();
      	}
      	return 0;
      }
      
      posted @ 2019-11-14 19:33  qscqesze  閱讀(734)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲综合一区二区三区视频| 欧美亚洲另类制服卡通动漫 | 中文无码精品a∨在线| 日韩精品福利视频在线观看| 亚洲国产精品自在拍在线播放蜜臀| 丰满熟妇人妻av无码区| 少妇人妻精品无码专区视频| 激情综合网激情五月俺也去| 国产sm重味一区二区三区| 日日碰狠狠添天天爽五月婷| 狠狠躁夜夜人人爽天96| 亚洲精品综合网中文字幕| 亚洲AV网一区二区三区| 国内极度色诱视频网站| 人人爽人人澡人人人妻| 国产精品中文字幕久久| ww污污污网站在线看com| 在线日韩日本国产亚洲| 亚洲综合一区二区三区| 亚洲午夜性猛春交XXXX| 澄迈县| 92国产精品午夜福利| 桃花岛亚洲成在人线AV| 亚洲婷婷综合色高清在线| 国产91丝袜在线观看| 国产成人亚洲精品狼色在线| 久久国产免费观看精品| 久久久久久综合网天天| 啊灬啊灬啊灬快灬高潮了电影片段| 日韩有码中文在线观看| 亚洲人成色7777在线观看不卡| 女人香蕉久久毛毛片精品| 国产精品亚洲中文字幕| 免费无码毛片一区二三区| 天堂资源在线| 色一伦一情一区二区三区| 国产精品高清一区二区三区| 午夜福利理论片高清在线| 亚洲一区二区三区日本久久| 丰满的女邻居2| 在线无码免费的毛片视频|