Esempio n. 1
0
 public void solve(int testNumber, MyInputReader in, MyOutputWriter out) {
   int n = in.nextInt();
   for (int i = 0; i < n; i++) {
     long v = in.nextLong();
     out.printLine(primeSet.contains(v) ? "YES" : "NO");
   }
 }
Esempio n. 2
0
  public void solve(int testNumber, MyInputReader in, MyOutputWriter out) {
    int n = in.nextInt();
    final int[] A = new int[n], C = new int[n];

    for (int i = 0; i < n; i++) {
      A[i] = in.nextInt();
    }
    long sum = 0;
    for (int i = 0; i < n; i++) {
      C[i] = in.nextInt();
      sum += C[i];
    }

    Integer[] order =
        ArrayUtils.order(
            n,
            new Comparator<Integer>() {
              @Override
              public int compare(Integer o1, Integer o2) {
                return A[o1] - A[o2];
              }
            });

    long ret = 0;

    for (int i = 1; i < n; i++) ret += (A[order[i]] - A[order[0]]) * C[order[i]];
    long presum = C[order[0]];
    long tmp = ret;
    for (int i = 1; i < n; i++) {
      int len = A[order[i]] - A[order[i - 1]];
      tmp = tmp + presum * len - (sum - presum) * len;
      ret = Math.min(ret, tmp);
      presum += C[order[i]];
    }
    out.printLine(ret);
  }