#include <iostream> #include <cstring> #include <string> #include <algorithm> #include <cstdio> using namespace std; #define maxn 10000 #define eps 1e-8 struct { int w, v; }a[maxn]; double b[maxn]; int n, k; bool cmp(double a, double b) { return a > b; } bool judge(double x) { cout<<x<<endl; double ans = 0.0; for(int i=0; i<n; i++) b[i] = a[i].v - x * a[i].w; sort(b, b+n, cmp); for(int i=0; i<n; i++) cout<<b[i]<<" "; cout<<endl; for(int i=0; i<k; i++) ans += b[i]; return ans >= 0; } void solve() { double L = 0; double R = 1000000; while((R - L) > eps) { double mid = (L + R) / 2; if(judge(mid)) L = mid; else R = mid; } cout<<L<<endl; } int main() { while(~scanf("%d%d", &n, &k)) { for(int i=0; i<n; i++) { scanf("%d%d", &a[i].w, &a[i].v); } solve(); } return 0; } /* 3 2 2 2 5 3 2 1 */
时间: 2024-10-07 01:02:39