Skip to content

Commit f53fa17

Browse files
committed
update
1 parent a19fefe commit f53fa17

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Time: 249 ms
2+
// Memory: 1500 KB
3+
// .
4+
// T:O(sum(logni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2126A_Only_One_Digit {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt(), ret = 9;
14+
while (n > 0) {
15+
ret = Math.min(ret, n % 10);
16+
n /= 10;
17+
}
18+
System.out.println(ret);
19+
}
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Time: 468 ms
2+
// Memory: 1000 KB
3+
// When no a[i] > b[i], the iteration stop, and one round you can only decrease single a[i] by 1, so sum the diff "a[i] - b[i]".
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2131A_Lever {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt();
14+
int[] a = new int[n], b = new int[n];
15+
for (int j = 0; j < n; j++) {
16+
a[j] = sc.nextInt();
17+
}
18+
for (int j = 0; j < n; j++) {
19+
b[j] = sc.nextInt();
20+
}
21+
int ret = 1;
22+
for (int j = 0; j < n; j++) {
23+
if (a[j] > b[j]) {
24+
ret += a[j] - b[j];
25+
}
26+
}
27+
28+
System.out.println(ret);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)