File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < algorithm>
4
+
5
+ using namespace std ;
6
+
7
+ int possible (vector <pair <long long , long long > > &L, long long x)
8
+ {
9
+ for (int i = 0 ; i < L.size (); i++)
10
+ {
11
+ if (x < L[i].first )
12
+ {
13
+ return false ;
14
+ }
15
+
16
+ x += L[i].second ;
17
+ }
18
+
19
+ return true ;
20
+ }
21
+
22
+ void solve ()
23
+ {
24
+ int no_of_levels;
25
+ cin >> no_of_levels;
26
+
27
+ vector <pair <long long , long long > > level;
28
+ for (int i = 1 ; i <= no_of_levels; i++)
29
+ {
30
+ int no_of_monsters;
31
+ cin >> no_of_monsters;
32
+
33
+ long long power = 0 , increment = no_of_monsters;
34
+ for (int j = 1 ; j <= no_of_monsters; j++)
35
+ {
36
+ long long x;
37
+ cin >> x;
38
+
39
+ power = max (power, x + 1 - (j - 1 ));
40
+ }
41
+
42
+ level.push_back (make_pair (power, increment));
43
+ }
44
+
45
+ sort (level.begin (), level.end ());
46
+
47
+ long long total_increment = 0 , power_required = 0 ;
48
+ for (int i = 0 ; i < no_of_levels; i++)
49
+ {
50
+ power_required = max (power_required, level[i].first - total_increment);
51
+ total_increment += level[i].second ;
52
+ }
53
+
54
+ cout << power_required << " \n " ;
55
+ }
56
+
57
+ int main ()
58
+ {
59
+ int no_of_test_cases;
60
+ cin >> no_of_test_cases;
61
+
62
+ while (no_of_test_cases--)
63
+ solve ();
64
+
65
+ return 0 ;
66
+ }
67
+
68
+
You can’t perform that action at this time.
0 commit comments