终于AC了。。。先睡觉。。。。。。
/*
* Copyright (c) 2019 Ng Kimbing, HNU, All rights reserved. May not be used, modified, or copied without permission.
* @Author: Ng Kimbing, HNU.
* @LastModified:2019-07-19 T 22:54:43.695 +08:00
*/
package NowCoder;
import java.util.Arrays;
import static ACMProblems.ACMIO.*;
public class ProblemC {
static class Fraction {
long molecule;
long denominator;
Fraction(long molecule, long denominator) {
this.molecule = molecule;
this.denominator = denominator;
}
void add(int num) {
this.molecule += num * this.denominator;
}
@Override
public String toString() {
if (this.denominator == 1)
return String.valueOf(this.molecule);
else return molecule + "/" + denominator;
}
void approximate() {
long gcd = gcd(molecule, denominator);
this.molecule /= gcd;
this.denominator /= gcd;
}
static long gcd(long a, long b) {
return b > 0 ? gcd(b, a % b) : a;
}
void divide(int m) {
this.denominator *= m;
}
}
private static int[] a = new int[10005];
private static long[] sum = new long[10005];
private static int n, m;
private static int findPos() {
for (int i = 0; i < n - 1; ++i)
if (a[i + 1] * (i + 1) < sum[i])
return i;
return n - 1;
}
public static void main(String[] args) {
while (true) {
try {
n = nextInt();
m = nextInt();
for (int i = 0; i < n; ++i)
a[i] = nextInt();
Arrays.sort(a, 0, n);
for (int i = 0, j = n - 1; i < j; ++i, --j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
sum[0] = a[0] - m;
for (int i = 1; i < n; ++i)
sum[i] = sum[i - 1] + a[i];
int pos = findPos();
// System.out.println("pos = " + pos);
Fraction ans = new Fraction(sum[pos] * sum[pos], pos + 1);
// System.out.println("org: " + ans);
for (int i = pos + 1; i < n; ++i)
ans.add(a[i] * a[i]);
// System.out.println("before divided " + ans);
ans.divide(m * m);
ans.approximate();
out.println(ans);
// out.flush();
Arrays.fill(sum, 0, n, 0);
} catch (Exception e) {
out.flush();
return;
}
}
}
}