Submission #58971
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 <= mv + a[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 | 1781 Byte |
Status | WA |
Exec Time | 2136 ms |
Memory | 62652 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 | WA | 1984 ms | 60696 KB |
02.txt | WA | 1946 ms | 55604 KB |
03.txt | TLE | 2040 ms | 62584 KB |
04.txt | TLE | 2039 ms | 60764 KB |
05.txt | WA | 1951 ms | 59864 KB |
06.txt | TLE | 2039 ms | 57844 KB |
07.txt | WA | 1974 ms | 59844 KB |
08.txt | TLE | 2039 ms | 60452 KB |
09.txt | TLE | 2062 ms | 60920 KB |
10.txt | TLE | 2038 ms | 60996 KB |
11.txt | TLE | 2039 ms | 62652 KB |
12.txt | TLE | 2046 ms | 60828 KB |
13.txt | TLE | 2039 ms | 60700 KB |
14.txt | TLE | 2072 ms | 60756 KB |
15.txt | TLE | 2028 ms | 60836 KB |
16.txt | TLE | 2024 ms | 60668 KB |
17.txt | TLE | 2038 ms | 59864 KB |
18.txt | TLE | 2047 ms | 60672 KB |
19.txt | WA | 1959 ms | 59852 KB |
20.txt | TLE | 2048 ms | 61160 KB |
20_minimal.txt | AC | 517 ms | 19540 KB |
21.txt | TLE | 2058 ms | 60728 KB |
22.txt | TLE | 2052 ms | 60692 KB |
23.txt | TLE | 2038 ms | 60808 KB |
24.txt | TLE | 2043 ms | 62484 KB |
25.txt | WA | 1977 ms | 59736 KB |
26.txt | TLE | 2042 ms | 60488 KB |
27.txt | TLE | 2136 ms | 61072 KB |
28.txt | TLE | 2056 ms | 60928 KB |
29.txt | TLE | 2038 ms | 62568 KB |
30.txt | TLE | 2039 ms | 60628 KB |
31.txt | TLE | 2039 ms | 58780 KB |
32.txt | TLE | 2102 ms | 60668 KB |
33.txt | TLE | 2079 ms | 60584 KB |
34.txt | TLE | 2062 ms | 60680 KB |
35.txt | TLE | 2053 ms | 62372 KB |
36.txt | TLE | 2040 ms | 61112 KB |
37.txt | TLE | 2082 ms | 60692 KB |
38.txt | TLE | 2041 ms | 62412 KB |
39.txt | TLE | 2084 ms | 62572 KB |
40.txt | TLE | 2039 ms | 62512 KB |
41.txt | WA | 1826 ms | 59672 KB |
42.txt | WA | 1453 ms | 57744 KB |
43.txt | AC | 962 ms | 21104 KB |
44.txt | WA | 2000 ms | 61088 KB |
45.txt | WA | 1708 ms | 60660 KB |
46.txt | WA | 1735 ms | 60456 KB |
47.txt | WA | 951 ms | 47484 KB |
48.txt | AC | 624 ms | 19660 KB |
49.txt | WA | 1887 ms | 60752 KB |
50.txt | WA | 1569 ms | 60716 KB |
51.txt | WA | 1931 ms | 60744 KB |
52.txt | TLE | 2044 ms | 60952 KB |
53.txt | TLE | 2039 ms | 62536 KB |
54.txt | TLE | 2043 ms | 61532 KB |
55.txt | WA | 1957 ms | 60968 KB |
56.txt | TLE | 2038 ms | 62432 KB |
57.txt | TLE | 2041 ms | 57120 KB |
58.txt | TLE | 2024 ms | 61112 KB |
59.txt | TLE | 2093 ms | 59488 KB |
60.txt | TLE | 2039 ms | 62272 KB |
dekai1.txt | WA | 1665 ms | 45860 KB |
dekai2.txt | TLE | 2071 ms | 60636 KB |
sample1.txt | AC | 563 ms | 19540 KB |
sample2.txt | AC | 692 ms | 19540 KB |
sample3.txt | AC | 676 ms | 19544 KB |
small01.txt | WA | 845 ms | 32816 KB |
small02.txt | WA | 545 ms | 19924 KB |
small03.txt | WA | 761 ms | 33440 KB |
small04.txt | WA | 739 ms | 20564 KB |
small05.txt | AC | 904 ms | 19536 KB |
small06.txt | WA | 763 ms | 28340 KB |
small07.txt | WA | 576 ms | 19676 KB |
small08.txt | WA | 885 ms | 31564 KB |
small09.txt | WA | 865 ms | 23748 KB |
small10.txt | WA | 747 ms | 32336 KB |
small11.txt | WA | 951 ms | 24380 KB |
small12.txt | WA | 791 ms | 19540 KB |
small13.txt | WA | 865 ms | 33528 KB |
small14.txt | WA | 661 ms | 23784 KB |
small15.txt | WA | 961 ms | 33216 KB |
small16.txt | WA | 728 ms | 30152 KB |
small17.txt | AC | 528 ms | 19540 KB |
small18.txt | WA | 689 ms | 30772 KB |
small19.txt | WA | 763 ms | 19696 KB |
small20.txt | WA | 757 ms | 31480 KB |
small21.txt | WA | 790 ms | 20336 KB |
small22.txt | WA | 764 ms | 32708 KB |
small23.txt | WA | 1130 ms | 20672 KB |
small24.txt | WA | 646 ms | 19540 KB |
small25.txt | WA | 722 ms | 25284 KB |
yabame1.txt | TLE | 2046 ms | 62364 KB |
yabame2.txt | TLE | 2052 ms | 60960 KB |
yabame3.txt | TLE | 2052 ms | 60944 KB |
yabame4.txt | TLE | 2078 ms | 60812 KB |