File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Expand file tree Collapse file tree 1 file changed +77
-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 left = 0 , right = 1e18 ;
48
+ while (right - left > 1 )
49
+ {
50
+ long long mid = (left + right)/2 ;
51
+
52
+ if (possible (level, mid))
53
+ {
54
+ right = mid;
55
+ }
56
+ else
57
+ {
58
+ left = mid;
59
+ }
60
+ }
61
+
62
+ cout << right << " \n " ;
63
+ }
64
+
65
+ int main ()
66
+ {
67
+ int no_of_test_cases;
68
+ cin >> no_of_test_cases;
69
+
70
+ while (no_of_test_cases--)
71
+ solve ();
72
+
73
+ return 0 ;
74
+ }
75
+
76
+
77
+
You can’t perform that action at this time.
0 commit comments