Skip to content

Commit 43b624f

Browse files
committed
feat(codeforces): implement solution for p2189B
1 parent 36da3b9 commit 43b624f

File tree

2 files changed

+49
-2
lines changed
  • src/main
    • java/com/lzw/solutions/codeforces/p2189B
    • resources/codeforces/p2198B

2 files changed

+49
-2
lines changed

src/main/java/com/lzw/solutions/codeforces/p2189B/Main.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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

0 commit comments

Comments
 (0)