Submission #935434
Source Code Expand
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Main().run(); } class Node { int w; int p; @Override public String toString() { return "{w = " + w + ", p = " + p + "}"; } } void run() { int n = ni(); int k = ni(); int[] w = new int[n]; int[] p = new int[n]; Node[] wp = new Node[n]; for (int i = 0; i < n; ++i) { w[i] = ni(); p[i] = ni(); Node node = new Node(); node.w = w[i]; node.p = p[i]; wp[i] = node; } double left = 0; double right = 100; while ((right - left) > 1e-9) { final double mid = (left + right) / 2.0; Arrays.sort(wp, new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { double a = o1.w * (o1.p - mid) / 100.0; double b = o2.w * (o2.p - mid) / 100.0; return Double.compare(b, a); } }); // debug(wp); long sum = 0; double sio = 0; for (int i = 0; i < k; ++i) { sio += wp[i].w * (wp[i].p / 100.0); sum += wp[i].w; } double per = sio / sum * 100; debug(sio, sum, per); if (per < mid) { right = mid; } else { left = mid; } } System.out.println((left + right) / 2.0); } int ni() { return Integer.parseInt(sc.next()); } void debug(Object... os) { System.err.println(Arrays.deepToString(os)); } /* class BIT<T> { int n; ArrayList<T> bit; BiFunction<T, T, T> bif; BIT(int n, BiFunction<T, T, T> bif, T defaultValue) { this.n = n; bit = new ArrayList<>(n + 1); for (int i = 0; i < n + 1; ++i) { bit.add(defaultValue); } this.bif = bif; } void update(int i, T v) { for (int x = i; x <= n; x += x & -x) { bit.set(x, bif.apply(bit.get(x), v)); } } T reduce(int i, T defaultValue) { T ret = defaultValue; for (int x = i; x > 0; x -= x & -x) { ret = bif.apply(ret, bit.get(x)); } return ret; } } */ long MOD = 1_000_000_007; long pow(long a, long r) { long sum = 1; while (r > 0) { if ((r & 1) == 1) { sum *= a; sum %= MOD; } a *= a; a %= MOD; r >>= 1; } return sum; } long C(int n, int r) { long sum = 1; for (int i = n; 0 < i; --i) { sum *= i; sum %= MOD; } long s = 1; for (int i = r; 0 < i; --i) { s *= i; s %= MOD; } sum *= pow(s, MOD - 2); sum %= MOD; long t = 1; for (int i = n - r; 0 < i; --i) { t *= i; t %= MOD; } sum *= pow(t, MOD - 2); sum %= MOD; return sum; } }
Submission Info
Submission Time | |
---|---|
Task | D - 食塩水 |
User | arukuka |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 2994 Byte |
Status | AC |
Exec Time | 434 ms |
Memory | 28616 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s0.txt, s1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, s0.txt, s1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 413 ms | 28264 KB |
001.txt | AC | 324 ms | 25940 KB |
002.txt | AC | 417 ms | 28404 KB |
003.txt | AC | 332 ms | 25944 KB |
004.txt | AC | 434 ms | 28408 KB |
005.txt | AC | 423 ms | 28580 KB |
006.txt | AC | 415 ms | 28616 KB |
007.txt | AC | 412 ms | 28208 KB |
008.txt | AC | 417 ms | 28504 KB |
009.txt | AC | 315 ms | 26004 KB |
010.txt | AC | 423 ms | 28588 KB |
011.txt | AC | 379 ms | 26744 KB |
012.txt | AC | 427 ms | 28388 KB |
013.txt | AC | 366 ms | 26548 KB |
014.txt | AC | 422 ms | 28324 KB |
015.txt | AC | 403 ms | 28068 KB |
016.txt | AC | 416 ms | 28388 KB |
017.txt | AC | 403 ms | 28168 KB |
018.txt | AC | 419 ms | 28616 KB |
019.txt | AC | 413 ms | 28208 KB |
s0.txt | AC | 293 ms | 24352 KB |
s1.txt | AC | 308 ms | 24892 KB |