#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define ld long double
#define ll long long
int n, k, I;
const int N = 507;
int A[N], B[N];
vector <pii> vA;
ld odpowiedz;
bool wziete[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i=1; i<=n; i++)
{
cin >> A[i] >> B[i];
if(B[i] != -1) I++;
vA.push_back({A[i], i});
}
I = min(I, k);
sort(vA.begin(), vA.end());
for(int i=1; i<=k; i++)
{
odpowiedz += (ld) vA[i-1].f;
}
cout << odpowiedz << endl;
for(int i=1; i<=I; i++)
{
vector <pii> ciagA;
for(int j=1; j<=n; j++) ciagA.push_back(vA[j-1]);
ld wynik = 0;
vector <ld> vBtmp;
for(int j=1; j<=i; j++)
{
ld minWyn = 10000000;
int kto = -1;
for(int o=1; o<=n; o++)
{
if(wziete[o] or B[o] == -1) continue;
ld tmp = ((ld) B[o] / (ld) j);
if(A[o] <= ciagA[k-i-1].f) tmp += ((ld)(ciagA[k-i].f - A[o]) / (ld)(i+1));
//cout << "tmp = " << ((ld)(ciagA[k-i].f - A[o]) / (ld)(i+1)) << endl;
if(minWyn > tmp)
{
minWyn = tmp;
kto = o;
}
}
//cout << "kto = " << kto << endl;
wziete[kto] = true;
wynik += (ld) B[kto] /(ld) j;
vBtmp.push_back((ld)B[kto]);
int tmpSize = ciagA.size();
for(int o=0; o<tmpSize; o++)
{
pii v = ciagA[o];
if(v.s == kto)
{
ciagA.erase(ciagA.begin() + o);
}
}
}
ld sumaA = 0;
for(int j=1; j<=k-i; j++)
{
sumaA += (ld) ciagA[j-1].f;
}
sumaA /= (ld)(i+1);
wynik = 0;
ld licznik = 1;
sort(vBtmp.begin(), vBtmp.end());
for(ld v : vBtmp)
{
wynik += v / licznik;
licznik = licznik + (ld) 1;
}
odpowiedz = min(odpowiedz, wynik + sumaA);
//cout << "wynik " << i << " = " << wynik << ", suma = " << sumaA << endl;
for(int j=1; j<=n; j++) wziete[j] = false;
}
cout << fixed << setprecision(5) << odpowiedz;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
208 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |