Submission #59109


Source Code Expand

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[] a, b;
	static long sum;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		N = sc.nextInt();
		a = new int[N];
		b = new int[N];
		long max = 0;
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			sum += a[i];
		}
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			ans = Math.max(ans, (long) Math.ceil(1.0 * (b[i] - 1) * sum / a[i]));
		}
		while (!possible(ans)) {
			++ans;
		}
		//		for (int i = 0; i < N; ++i) {
		//			long mv = (long) Math.ceil(1.0 * (b[i] - 1) * sum / a[i]);
		//			for (long j = mv; j < ans && a[i] * j / sum <= b[i]; ++j) {
		//				if (possible(j)) {
		//					ans = Math.min(ans, j);
		//					break;
		//				}
		//			}
		//		}
		//		long ans = max;
		//		for (long i = max; i >= 0 && System.currentTimeMillis() - start < 1900; --i) {
		//			if (possible(i)) {
		//				ans = i;
		//			}
		//		}
		System.out.println(ans);
	}

	static boolean possible(long m) {
		long[] count = new long[N];
		long all = 0;
		St[] rem = new St[N];
		boolean ok = true;
		for (int i = 0; i < N; ++i) {
			count[i] = a[i] * m / sum;
			all += count[i];
			rem[i] = new St(a[i] * m - count[i] * sum, i);
			if (count[i] < b[i]) ok = false;
		}
		if (ok) return true;
		Arrays.sort(rem);
		for (int i = 0; i < Math.min(m - all, N); ++i) {
			++count[rem[i].i];
		}
		//		System.out.println(m + " " + Arrays.toString(count) + " " + all);
		for (int i = 0; i < N; ++i) {
			if (count[i] < b[i]) return false;
		}
		return true;
	}

	static class St implements Comparable<St> {
		long c;
		int i;

		St(long c, int i) {
			this.c = c;
			this.i = i;
		}

		public int compareTo(St o) {
			if (this.c == o.c) return this.i - o.i;
			if (this.c > o.c) return -1;
			return 1;
		}
	}

}

Submission Info

Submission Time
Task E - 選挙
User tomerun
Language Java (OpenJDK 1.7.0)
Score 200
Code Size 1985 Byte
Status AC
Exec Time 1891 ms
Memory 63172 KB

Judge Result

Set Name Bubunten All
Score / Max Score 50 / 50 150 / 150
Status
AC × 29
AC × 92
Set Name Test Cases
Bubunten small01.txt, small02.txt, small03.txt, small04.txt, small05.txt, small06.txt, small07.txt, small08.txt, small09.txt, small10.txt, small11.txt, small12.txt, small13.txt, small14.txt, small15.txt, small16.txt, small17.txt, small18.txt, small19.txt, small20.txt, small21.txt, small22.txt, small23.txt, small24.txt, small25.txt, sample1.txt, sample2.txt, sample3.txt, 20_minimal.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 20_minimal.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, dekai1.txt, dekai2.txt, small01.txt, small02.txt, small03.txt, small04.txt, small05.txt, small06.txt, small07.txt, small08.txt, small09.txt, small10.txt, small11.txt, small12.txt, small13.txt, small14.txt, small15.txt, small16.txt, small17.txt, small18.txt, small19.txt, small20.txt, small21.txt, small22.txt, small23.txt, small24.txt, small25.txt, yabame1.txt, yabame2.txt, yabame3.txt, yabame4.txt
Case Name Status Exec Time Memory
01.txt AC 1455 ms 61264 KB
02.txt AC 1567 ms 61316 KB
03.txt AC 971 ms 53464 KB
04.txt AC 727 ms 42920 KB
05.txt AC 1411 ms 56352 KB
06.txt AC 1283 ms 61364 KB
07.txt AC 738 ms 39812 KB
08.txt AC 1600 ms 60380 KB
09.txt AC 1635 ms 61304 KB
10.txt AC 949 ms 54600 KB
11.txt AC 777 ms 45756 KB
12.txt AC 686 ms 36504 KB
13.txt AC 933 ms 51832 KB
14.txt AC 696 ms 39044 KB
15.txt AC 859 ms 49468 KB
16.txt AC 533 ms 27648 KB
17.txt AC 1494 ms 61168 KB
18.txt AC 1295 ms 61400 KB
19.txt AC 909 ms 51948 KB
20.txt AC 698 ms 38960 KB
20_minimal.txt AC 462 ms 20068 KB
21.txt AC 822 ms 42384 KB
22.txt AC 1481 ms 61684 KB
23.txt AC 1312 ms 61368 KB
24.txt AC 823 ms 47108 KB
25.txt AC 577 ms 31960 KB
26.txt AC 775 ms 39632 KB
27.txt AC 758 ms 41464 KB
28.txt AC 634 ms 34964 KB
29.txt AC 946 ms 51912 KB
30.txt AC 673 ms 37404 KB
31.txt AC 691 ms 38768 KB
32.txt AC 711 ms 39220 KB
33.txt AC 569 ms 30800 KB
34.txt AC 582 ms 32076 KB
35.txt AC 714 ms 38712 KB
36.txt AC 742 ms 41060 KB
37.txt AC 934 ms 52400 KB
38.txt AC 703 ms 39724 KB
39.txt AC 738 ms 42868 KB
40.txt AC 855 ms 44552 KB
41.txt AC 983 ms 52000 KB
42.txt AC 480 ms 20724 KB
43.txt AC 489 ms 20124 KB
44.txt AC 622 ms 34056 KB
45.txt AC 581 ms 31104 KB
46.txt AC 540 ms 23496 KB
47.txt AC 573 ms 32228 KB
48.txt AC 459 ms 20144 KB
49.txt AC 988 ms 52772 KB
50.txt AC 579 ms 32228 KB
51.txt AC 1495 ms 61332 KB
52.txt AC 1664 ms 61240 KB
53.txt AC 1750 ms 63172 KB
54.txt AC 1563 ms 61604 KB
55.txt AC 1571 ms 61252 KB
56.txt AC 1639 ms 61316 KB
57.txt AC 1571 ms 61412 KB
58.txt AC 1753 ms 62808 KB
59.txt AC 1720 ms 61440 KB
60.txt AC 1714 ms 63156 KB
dekai1.txt AC 658 ms 37516 KB
dekai2.txt AC 666 ms 38008 KB
sample1.txt AC 469 ms 20144 KB
sample2.txt AC 461 ms 20200 KB
sample3.txt AC 468 ms 20140 KB
small01.txt AC 518 ms 23608 KB
small02.txt AC 483 ms 20144 KB
small03.txt AC 468 ms 22068 KB
small04.txt AC 468 ms 20276 KB
small05.txt AC 512 ms 20144 KB
small06.txt AC 482 ms 20656 KB
small07.txt AC 481 ms 20272 KB
small08.txt AC 499 ms 23212 KB
small09.txt AC 474 ms 20920 KB
small10.txt AC 488 ms 22272 KB
small11.txt AC 516 ms 23980 KB
small12.txt AC 461 ms 20144 KB
small13.txt AC 507 ms 26880 KB
small14.txt AC 480 ms 20232 KB
small15.txt AC 547 ms 29252 KB
small16.txt AC 500 ms 20784 KB
small17.txt AC 455 ms 20124 KB
small18.txt AC 465 ms 20200 KB
small19.txt AC 465 ms 20252 KB
small20.txt AC 469 ms 20788 KB
small21.txt AC 475 ms 20660 KB
small22.txt AC 495 ms 22756 KB
small23.txt AC 486 ms 20676 KB
small24.txt AC 450 ms 20020 KB
small25.txt AC 513 ms 23268 KB
yabame1.txt AC 1845 ms 62892 KB
yabame2.txt AC 1710 ms 61688 KB
yabame3.txt AC 1891 ms 63052 KB
yabame4.txt AC 1857 ms 61436 KB