Submission #59014


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 = 1L << 60;
		for (int i = 0; i < N; ++i) {
			long mv = (long) Math.ceil(1.0 * (b[i] - 1) * sum / a[i]);
			for (long j = mv; 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 0
Code Size 1788 Byte
Status WA
Exec Time 2049 ms
Memory 63452 KB

Judge Result

Set Name Bubunten All
Score / Max Score 0 / 50 0 / 150
Status
AC × 25
WA × 4
AC × 76
WA × 3
TLE × 13
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 1754 ms 61552 KB
02.txt TLE 2047 ms 61536 KB
03.txt AC 1770 ms 61528 KB
04.txt AC 1767 ms 63288 KB
05.txt AC 1868 ms 61944 KB
06.txt AC 1789 ms 61560 KB
07.txt AC 1713 ms 61540 KB
08.txt TLE 2046 ms 61464 KB
09.txt AC 1929 ms 61620 KB
10.txt AC 1643 ms 61388 KB
11.txt AC 1686 ms 61400 KB
12.txt AC 1688 ms 61452 KB
13.txt AC 1720 ms 61532 KB
14.txt AC 1893 ms 61536 KB
15.txt AC 1625 ms 61576 KB
16.txt AC 1642 ms 61664 KB
17.txt AC 1756 ms 59764 KB
18.txt AC 1759 ms 61460 KB
19.txt AC 1776 ms 63276 KB
20.txt AC 1981 ms 61224 KB
20_minimal.txt WA 477 ms 20244 KB
21.txt AC 1818 ms 63404 KB
22.txt AC 1718 ms 61676 KB
23.txt AC 1974 ms 61384 KB
24.txt AC 1726 ms 61292 KB
25.txt AC 1799 ms 63336 KB
26.txt AC 1593 ms 61572 KB
27.txt AC 1721 ms 61396 KB
28.txt AC 1882 ms 61444 KB
29.txt AC 1824 ms 63400 KB
30.txt AC 1740 ms 63452 KB
31.txt AC 1869 ms 61432 KB
32.txt AC 1780 ms 61688 KB
33.txt AC 1680 ms 61416 KB
34.txt AC 1594 ms 61752 KB
35.txt AC 1870 ms 63228 KB
36.txt AC 1843 ms 61448 KB
37.txt AC 1883 ms 63032 KB
38.txt AC 1804 ms 61392 KB
39.txt AC 1873 ms 63216 KB
40.txt AC 1804 ms 63344 KB
41.txt AC 1274 ms 60208 KB
42.txt AC 668 ms 34840 KB
43.txt AC 484 ms 20284 KB
44.txt AC 1664 ms 61452 KB
45.txt AC 1551 ms 61692 KB
46.txt AC 811 ms 48208 KB
47.txt AC 666 ms 35232 KB
48.txt AC 457 ms 20368 KB
49.txt AC 1750 ms 61980 KB
50.txt AC 1505 ms 61312 KB
51.txt TLE 2047 ms 62184 KB
52.txt TLE 2049 ms 61416 KB
53.txt TLE 2047 ms 61600 KB
54.txt TLE 2046 ms 63072 KB
55.txt TLE 2049 ms 61696 KB
56.txt TLE 2047 ms 63116 KB
57.txt TLE 2047 ms 63156 KB
58.txt TLE 2046 ms 61784 KB
59.txt TLE 2046 ms 63156 KB
60.txt TLE 2047 ms 62900 KB
dekai1.txt AC 1150 ms 46648 KB
dekai2.txt AC 1040 ms 45220 KB
sample1.txt AC 471 ms 20368 KB
sample2.txt AC 458 ms 20364 KB
sample3.txt WA 459 ms 20292 KB
small01.txt AC 700 ms 39528 KB
small02.txt AC 488 ms 21264 KB
small03.txt AC 700 ms 34908 KB
small04.txt AC 522 ms 27440 KB
small05.txt WA 461 ms 20240 KB
small06.txt AC 571 ms 32296 KB
small07.txt AC 470 ms 20304 KB
small08.txt AC 705 ms 39152 KB
small09.txt AC 501 ms 23192 KB
small10.txt AC 828 ms 47388 KB
small11.txt AC 702 ms 35736 KB
small12.txt AC 495 ms 20384 KB
small13.txt AC 991 ms 49472 KB
small14.txt AC 507 ms 23568 KB
small15.txt AC 798 ms 43928 KB
small16.txt AC 528 ms 26460 KB
small17.txt WA 460 ms 20244 KB
small18.txt AC 564 ms 31712 KB
small19.txt AC 477 ms 20376 KB
small20.txt AC 710 ms 39684 KB
small21.txt AC 512 ms 24204 KB
small22.txt AC 785 ms 43356 KB
small23.txt AC 586 ms 32328 KB
small24.txt AC 456 ms 20288 KB
small25.txt AC 633 ms 34888 KB
yabame1.txt TLE 2046 ms 63096 KB
yabame2.txt AC 1979 ms 63092 KB
yabame3.txt AC 1922 ms 60000 KB
yabame4.txt AC 1835 ms 61796 KB