Yet Another Monster Killing Problem

for (int i = n; i >= 0; i--) k[i] = max(k[i], k[i + 1]);

for (; j <= n; j++) {
maxn = max(maxn, a[j + i]);
if (k[j + 1] < maxn) break; //因为每个英雄可以无限次使用
}
day++;
i += j;

每天都会生成新的耐力值

 1 #include<cstdio>
2 #include<iostream>
3 #include<cstring>
4 #include<algorithm>
5 #include<queue>
6 #include<stack>
7 #include <bitset>
8 #include<set>
9 #include<map>
10 #include<unordered_map>
11 #include<vector>
12 #include<cmath>
13 #include<string>
14 using namespace std;
15 typedef long long ll;
16 #define inf 99999999
17 const int maxn = 2e5;
18 int t, n, m;
19 int a[maxn], k[maxn];
20 struct node {
21     int p;
22     int s;
23 }her[maxn];
24 int main() {
25     cin >> t;
26     while(t--){
27         cin >> n;
28         for (int i = 1; i <= n; i++) {
29             cin >> a[i];
30         }
31         cin >> m;
32         for (int i = 1; i <= m; i++) {
33             cin >> her[i].p >> her[i].s;
34             //记录每个耐力值的最大攻击力值
35             k[her[i].s] = max(k[her[i].s], her[i].p);
36         }
37         for (int i = n; i >= 0; i--) k[i] = max(k[i], k[i + 1]);
38         int day = 0;
39         int f = 0;
40         for (int i = 1; i <= n;) {
41             if (a[i] > k[1]) {
42                 f = 1;
43                 cout << "-1" << endl;
44                 break;
45             }
46             int j = 0;
47             int maxn = 0;
48             for (; j <= n; j++) {
49                 maxn = max(maxn, a[j + i]);
50                 if (k[j + 1] < maxn) break; //因为每个英雄可以无限次使用
51             }
52             day++;
53             i += j;
54         }
55         if (f == 0) {
56             cout << day << endl;
57         }
58         for (int i = 0; i <= n; i++) k[i] = 0;
59     }
60     return 0;
61 }

posted @ 2020-07-28 11:15  吉吉的奥利奥  阅读(26)  评论(0编辑  收藏