File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
java/com/lzw/solutions/codeforces/p2189B
resources/codeforces/p2198B Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,40 @@ public class Main {
1010 private static final PrintWriter out = new PrintWriter (System .out , true );
1111
1212 private static void solve () throws IOException {
13- // your code here
13+ String line = in .readLine ().trim ();
14+ int t = Integer .parseInt (line );
15+ for (int test = 0 ; test < t ; test ++) {
16+ line = in .readLine ().trim ();
17+ String [] parts = line .split ("\\ s+" );
18+ int n = Integer .parseInt (parts [0 ]);
19+ long x = Long .parseLong (parts [1 ]);
20+ long free = 0 ;
21+ long maxp = 0 ;
22+ for (int i = 0 ; i < n ; i ++) {
23+ line = in .readLine ().trim ();
24+ parts = line .split ("\\ s+" );
25+ long a = Long .parseLong (parts [0 ]);
26+ long b = Long .parseLong (parts [1 ]);
27+ long c = Long .parseLong (parts [2 ]);
28+ free += (b - 1 ) * a ;
29+ long p = b * a - c ;
30+ maxp = Math .max (maxp , p );
31+ }
32+ long ans ;
33+ if (free >= x ) {
34+ ans = 0 ;
35+ } else if (maxp <= 0 ) {
36+ ans = -1 ;
37+ } else {
38+ long need = x - free ;
39+ ans = (need + maxp - 1 ) / maxp ;
40+ }
41+ out .println (ans );
42+ }
1443 }
1544
1645 public static void main (String [] args ) throws IOException {
1746 solve ();
1847 out .close ();
1948 }
20- }
49+ }
Original file line number Diff line number Diff line change 1+ 6
2+ 1 1
3+ 3 3 3
4+ 1 7
5+ 4 2 5
6+ 2 4
7+ 1 2 3
8+ 2 2 4
9+ 5 8
10+ 12 1 11
11+ 10 1 4
12+ 1 1 3
13+ 1 2 5
14+ 2 1 7
15+ 1 1000000000000000000
16+ 1000000 4 654321
17+ 1 10
18+ 2 2 1
You can’t perform that action at this time.
0 commit comments