Submission #58410
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]; } for (int i = 0; i < N; ++i) { max = Math.max(max, (sum * (b[i] + 1) + sum - 1) / a[i]); } 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 | 1607 Byte |
Status | TLE |
Exec Time | 2149 ms |
Memory | 61604 KB |
Judge Result
Set Name | Bubunten | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 50 | 0 / 150 | ||||||||
Status |
|
|
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 | TLE | 2039 ms | 59288 KB |
02.txt | TLE | 2038 ms | 56712 KB |
03.txt | TLE | 2040 ms | 58472 KB |
04.txt | TLE | 2039 ms | 61284 KB |
05.txt | TLE | 2055 ms | 60788 KB |
06.txt | TLE | 2040 ms | 59296 KB |
07.txt | TLE | 2039 ms | 59176 KB |
08.txt | TLE | 2039 ms | 59404 KB |
09.txt | TLE | 2069 ms | 59560 KB |
10.txt | TLE | 2040 ms | 61136 KB |
11.txt | TLE | 2040 ms | 59328 KB |
12.txt | TLE | 2040 ms | 56600 KB |
13.txt | TLE | 2039 ms | 60996 KB |
14.txt | TLE | 2040 ms | 58536 KB |
15.txt | TLE | 2040 ms | 61228 KB |
16.txt | TLE | 2039 ms | 59464 KB |
17.txt | TLE | 2039 ms | 61132 KB |
18.txt | TLE | 2040 ms | 59348 KB |
19.txt | TLE | 2095 ms | 58352 KB |
20.txt | TLE | 2038 ms | 59616 KB |
20_minimal.txt | AC | 468 ms | 18040 KB |
21.txt | TLE | 2041 ms | 60960 KB |
22.txt | TLE | 2045 ms | 61604 KB |
23.txt | TLE | 2097 ms | 61004 KB |
24.txt | TLE | 2057 ms | 59168 KB |
25.txt | TLE | 2119 ms | 59540 KB |
26.txt | TLE | 2122 ms | 58920 KB |
27.txt | TLE | 2083 ms | 59384 KB |
28.txt | TLE | 2066 ms | 58240 KB |
29.txt | TLE | 2039 ms | 59212 KB |
30.txt | TLE | 2041 ms | 59236 KB |
31.txt | TLE | 2058 ms | 59292 KB |
32.txt | TLE | 2044 ms | 59552 KB |
33.txt | TLE | 2044 ms | 59044 KB |
34.txt | TLE | 2039 ms | 56836 KB |
35.txt | TLE | 2039 ms | 59408 KB |
36.txt | TLE | 2040 ms | 59640 KB |
37.txt | TLE | 2101 ms | 58556 KB |
38.txt | TLE | 2103 ms | 60992 KB |
39.txt | TLE | 2040 ms | 59284 KB |
40.txt | TLE | 2096 ms | 59284 KB |
41.txt | TLE | 2043 ms | 60452 KB |
42.txt | TLE | 2039 ms | 59952 KB |
43.txt | TLE | 2036 ms | 29480 KB |
44.txt | TLE | 2041 ms | 60160 KB |
45.txt | TLE | 2047 ms | 59296 KB |
46.txt | TLE | 2098 ms | 58784 KB |
47.txt | TLE | 2039 ms | 60300 KB |
48.txt | TLE | 2042 ms | 31668 KB |
49.txt | TLE | 2044 ms | 59400 KB |
50.txt | TLE | 2103 ms | 59184 KB |
51.txt | TLE | 2042 ms | 60132 KB |
52.txt | TLE | 2083 ms | 61416 KB |
53.txt | TLE | 2090 ms | 58388 KB |
54.txt | TLE | 2073 ms | 61224 KB |
55.txt | TLE | 2149 ms | 59212 KB |
56.txt | TLE | 2039 ms | 60988 KB |
57.txt | TLE | 2124 ms | 60056 KB |
58.txt | TLE | 2106 ms | 61304 KB |
59.txt | TLE | 2119 ms | 61056 KB |
60.txt | TLE | 2068 ms | 54972 KB |
dekai1.txt | TLE | 2086 ms | 53616 KB |
dekai2.txt | TLE | 2079 ms | 42604 KB |
sample1.txt | AC | 491 ms | 17992 KB |
sample2.txt | AC | 419 ms | 18012 KB |
sample3.txt | AC | 426 ms | 17928 KB |
small01.txt | AC | 1577 ms | 59008 KB |
small02.txt | AC | 500 ms | 25112 KB |
small03.txt | AC | 492 ms | 20864 KB |
small04.txt | AC | 542 ms | 29132 KB |
small05.txt | AC | 425 ms | 18048 KB |
small06.txt | AC | 523 ms | 29744 KB |
small07.txt | AC | 464 ms | 22460 KB |
small08.txt | AC | 1944 ms | 58508 KB |
small09.txt | AC | 1419 ms | 57952 KB |
small10.txt | AC | 815 ms | 42396 KB |
small11.txt | AC | 1806 ms | 53816 KB |
small12.txt | AC | 524 ms | 23116 KB |
small13.txt | AC | 1925 ms | 61252 KB |
small14.txt | AC | 520 ms | 19176 KB |
small15.txt | TLE | 2067 ms | 59168 KB |
small16.txt | AC | 639 ms | 33420 KB |
small17.txt | AC | 471 ms | 18016 KB |
small18.txt | AC | 641 ms | 33032 KB |
small19.txt | AC | 559 ms | 26864 KB |
small20.txt | AC | 582 ms | 33308 KB |
small21.txt | AC | 988 ms | 53520 KB |
small22.txt | AC | 781 ms | 38928 KB |
small23.txt | AC | 538 ms | 29212 KB |
small24.txt | AC | 451 ms | 19424 KB |
small25.txt | AC | 654 ms | 37176 KB |
yabame1.txt | TLE | 2115 ms | 59896 KB |
yabame2.txt | TLE | 2113 ms | 56744 KB |
yabame3.txt | TLE | 2090 ms | 59764 KB |
yabame4.txt | TLE | 2101 ms | 60728 KB |