|
| 1 | +import java.io.ByteArrayInputStream; |
| 2 | +import java.io.IOException; |
| 3 | +import java.io.InputStream; |
| 4 | +import java.io.PrintWriter; |
| 5 | +import java.math.BigInteger; |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.InputMismatchException; |
| 8 | + |
| 9 | +public class B { |
| 10 | + InputStream is; |
| 11 | + PrintWriter out; |
| 12 | + String INPUT = "2 1 2\n" + |
| 13 | + "1 2\n" + |
| 14 | + "3 1"; |
| 15 | + |
| 16 | + private void solve() { |
| 17 | + long n = nl(); |
| 18 | + long m = nl(); |
| 19 | + long k = nl(); |
| 20 | + long ans = -1, max = -0x3f3f3f3f3f3f3f3fL; |
| 21 | + for (long i = 0; i < k; i++) |
| 22 | + { |
| 23 | + long a = nl(), b = nl(); |
| 24 | + if (a * m + (n - m) * b >= max) { |
| 25 | + max = a * m + (n - m) * b; |
| 26 | + ans = i; |
| 27 | + } |
| 28 | + } |
| 29 | + for (long i = 0; i < k; i++) |
| 30 | + out.printf("%d%c", i == ans ? n : 0, i == k - 1 ? '\n' : ' '); |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + void run() throws Exception |
| 35 | + { |
| 36 | + is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); |
| 37 | + out = new PrintWriter(System.out); |
| 38 | + |
| 39 | + long s = System.currentTimeMillis(); |
| 40 | + solve(); |
| 41 | + out.flush(); |
| 42 | + tr(System.currentTimeMillis()-s+"ms"); |
| 43 | + } |
| 44 | + |
| 45 | + public static void main(String[] args) throws Exception { new B().run(); } |
| 46 | + |
| 47 | + private byte[] inbuf = new byte[1024]; |
| 48 | + public int lenbuf = 0, ptrbuf = 0; |
| 49 | + |
| 50 | + private int readByte() |
| 51 | + { |
| 52 | + if(lenbuf == -1)throw new InputMismatchException(); |
| 53 | + if(ptrbuf >= lenbuf){ |
| 54 | + ptrbuf = 0; |
| 55 | + try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } |
| 56 | + if(lenbuf <= 0)return -1; |
| 57 | + } |
| 58 | + return inbuf[ptrbuf++]; |
| 59 | + } |
| 60 | + |
| 61 | + private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } |
| 62 | + private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } |
| 63 | + |
| 64 | + private double nd() { return Double.parseDouble(ns()); } |
| 65 | + private char nc() { return (char)skip(); } |
| 66 | + |
| 67 | + private String ns() |
| 68 | + { |
| 69 | + int b = skip(); |
| 70 | + StringBuilder sb = new StringBuilder(); |
| 71 | + while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') |
| 72 | + sb.appendCodePoint(b); |
| 73 | + b = readByte(); |
| 74 | + } |
| 75 | + return sb.toString(); |
| 76 | + } |
| 77 | + |
| 78 | + private char[] ns(int n) |
| 79 | + { |
| 80 | + char[] buf = new char[n]; |
| 81 | + int b = skip(), p = 0; |
| 82 | + while(p < n && !(isSpaceChar(b))){ |
| 83 | + buf[p++] = (char)b; |
| 84 | + b = readByte(); |
| 85 | + } |
| 86 | + return n == p ? buf : Arrays.copyOf(buf, p); |
| 87 | + } |
| 88 | + |
| 89 | + private char[][] nm(int n, int m) |
| 90 | + { |
| 91 | + char[][] map = new char[n][]; |
| 92 | + for(int i = 0;i < n;i++)map[i] = ns(m); |
| 93 | + return map; |
| 94 | + } |
| 95 | + |
| 96 | + private int[] na(int n) |
| 97 | + { |
| 98 | + int[] a = new int[n]; |
| 99 | + for(int i = 0;i < n;i++)a[i] = ni(); |
| 100 | + return a; |
| 101 | + } |
| 102 | + |
| 103 | + private int ni() |
| 104 | + { |
| 105 | + int num = 0, b; |
| 106 | + boolean minus = false; |
| 107 | + while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); |
| 108 | + if(b == '-'){ |
| 109 | + minus = true; |
| 110 | + b = readByte(); |
| 111 | + } |
| 112 | + |
| 113 | + while(true){ |
| 114 | + if(b >= '0' && b <= '9'){ |
| 115 | + num = num * 10 + (b - '0'); |
| 116 | + }else{ |
| 117 | + return minus ? -num : num; |
| 118 | + } |
| 119 | + b = readByte(); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + private long nl() |
| 124 | + { |
| 125 | + long num = 0; |
| 126 | + int b; |
| 127 | + boolean minus = false; |
| 128 | + while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); |
| 129 | + if(b == '-'){ |
| 130 | + minus = true; |
| 131 | + b = readByte(); |
| 132 | + } |
| 133 | + |
| 134 | + while(true){ |
| 135 | + if(b >= '0' && b <= '9'){ |
| 136 | + num = num * 10 + (b - '0'); |
| 137 | + }else{ |
| 138 | + return minus ? -num : num; |
| 139 | + } |
| 140 | + b = readByte(); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + private boolean oj = true; |
| 145 | + |
| 146 | + //private boolean oj = System.getProperty("ONLINE_JUDGE") != null; |
| 147 | + private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } |
| 148 | +} |
0 commit comments