Submission #58901
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;; ++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 | 1766 Byte |
Status | TLE |
Exec Time | 2122 ms |
Memory | 64428 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 | 2040 ms | 61316 KB |
02.txt | TLE | 2060 ms | 61252 KB |
03.txt | TLE | 2049 ms | 61244 KB |
04.txt | TLE | 2040 ms | 60416 KB |
05.txt | TLE | 2050 ms | 61548 KB |
06.txt | TLE | 2046 ms | 63148 KB |
07.txt | TLE | 2041 ms | 60428 KB |
08.txt | TLE | 2040 ms | 58600 KB |
09.txt | TLE | 2061 ms | 61900 KB |
10.txt | TLE | 2079 ms | 61176 KB |
11.txt | TLE | 2039 ms | 61284 KB |
12.txt | TLE | 2069 ms | 61324 KB |
13.txt | TLE | 2083 ms | 60440 KB |
14.txt | TLE | 2051 ms | 62108 KB |
15.txt | TLE | 2040 ms | 61344 KB |
16.txt | TLE | 2040 ms | 61340 KB |
17.txt | TLE | 2040 ms | 61360 KB |
18.txt | TLE | 2039 ms | 61648 KB |
19.txt | TLE | 2039 ms | 61228 KB |
20.txt | TLE | 2114 ms | 61224 KB |
20_minimal.txt | AC | 477 ms | 20056 KB |
21.txt | TLE | 2040 ms | 61308 KB |
22.txt | TLE | 2041 ms | 63224 KB |
23.txt | TLE | 2041 ms | 61288 KB |
24.txt | TLE | 2040 ms | 60352 KB |
25.txt | TLE | 2041 ms | 61504 KB |
26.txt | TLE | 2084 ms | 61568 KB |
27.txt | TLE | 2082 ms | 61312 KB |
28.txt | TLE | 2039 ms | 61308 KB |
29.txt | TLE | 2083 ms | 61200 KB |
30.txt | TLE | 2079 ms | 63212 KB |
31.txt | TLE | 2104 ms | 61772 KB |
32.txt | TLE | 2043 ms | 61368 KB |
33.txt | TLE | 2092 ms | 60664 KB |
34.txt | TLE | 2092 ms | 63228 KB |
35.txt | TLE | 2039 ms | 61252 KB |
36.txt | TLE | 2076 ms | 61220 KB |
37.txt | TLE | 2064 ms | 60716 KB |
38.txt | TLE | 2039 ms | 61208 KB |
39.txt | TLE | 2045 ms | 61700 KB |
40.txt | TLE | 2040 ms | 61420 KB |
41.txt | TLE | 2039 ms | 62576 KB |
42.txt | TLE | 2042 ms | 60712 KB |
43.txt | TLE | 2068 ms | 31776 KB |
44.txt | TLE | 2095 ms | 61316 KB |
45.txt | TLE | 2041 ms | 61584 KB |
46.txt | TLE | 2040 ms | 60940 KB |
47.txt | TLE | 2079 ms | 60324 KB |
48.txt | TLE | 2037 ms | 33340 KB |
49.txt | TLE | 2096 ms | 60464 KB |
50.txt | TLE | 2040 ms | 61312 KB |
51.txt | TLE | 2042 ms | 61732 KB |
52.txt | TLE | 2087 ms | 61776 KB |
53.txt | TLE | 2042 ms | 61436 KB |
54.txt | TLE | 2039 ms | 62944 KB |
55.txt | TLE | 2096 ms | 61500 KB |
56.txt | TLE | 2040 ms | 61704 KB |
57.txt | TLE | 2122 ms | 61568 KB |
58.txt | TLE | 2042 ms | 59244 KB |
59.txt | TLE | 2054 ms | 63036 KB |
60.txt | TLE | 2056 ms | 62872 KB |
dekai1.txt | TLE | 2076 ms | 46488 KB |
dekai2.txt | TLE | 2052 ms | 61520 KB |
sample1.txt | AC | 465 ms | 20052 KB |
sample2.txt | AC | 442 ms | 20008 KB |
sample3.txt | AC | 453 ms | 20136 KB |
small01.txt | TLE | 2040 ms | 60792 KB |
small02.txt | AC | 721 ms | 39704 KB |
small03.txt | AC | 1554 ms | 63156 KB |
small04.txt | AC | 986 ms | 50860 KB |
small05.txt | AC | 459 ms | 20060 KB |
small06.txt | AC | 1093 ms | 52412 KB |
small07.txt | AC | 603 ms | 34800 KB |
small08.txt | TLE | 2039 ms | 60716 KB |
small09.txt | TLE | 2039 ms | 60576 KB |
small10.txt | AC | 1823 ms | 63256 KB |
small11.txt | TLE | 2050 ms | 61504 KB |
small12.txt | AC | 555 ms | 29564 KB |
small13.txt | TLE | 2076 ms | 62328 KB |
small14.txt | AC | 928 ms | 51972 KB |
small15.txt | TLE | 2076 ms | 64428 KB |
small16.txt | AC | 1450 ms | 60660 KB |
small17.txt | AC | 466 ms | 20140 KB |
small18.txt | AC | 1455 ms | 60616 KB |
small19.txt | AC | 721 ms | 38288 KB |
small20.txt | AC | 1400 ms | 60536 KB |
small21.txt | AC | 1691 ms | 60572 KB |
small22.txt | AC | 1910 ms | 63112 KB |
small23.txt | AC | 1122 ms | 55564 KB |
small24.txt | AC | 502 ms | 25100 KB |
small25.txt | AC | 1618 ms | 60864 KB |
yabame1.txt | TLE | 2041 ms | 61700 KB |
yabame2.txt | TLE | 2044 ms | 62924 KB |
yabame3.txt | TLE | 2051 ms | 61884 KB |
yabame4.txt | TLE | 2076 ms | 61180 KB |