#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define f first
#define s second
#define ld long double
ll n, k, I;
ld odpowiedz = 10000000;
const ll N = 507, dupsko = 213769420;
ll A[N], B[N];
ld kosztB[N][N];
ll maxA[N][N];
ll nextMaxA[N][N];
vector <ll> ciagA[N][N];
ll sumaA[N][N];
vector <pii> tab = {{-10,-10}};
bool cmpB(pii a, pii b)
{
return a.s < b.s;
}
bool cmpA(ll a, ll b)
{
return tab[a].f < tab[b].f;
}
void ustal_odp()
{
vector <ll> tmpA;
ld tmpOdp = 0;
for(ll i=1; i<=n; i++) tmpA.push_back(A[i]);
sort(tmpA.begin(), tmpA.end());
for(ll i=0; i<k; i++)
{
tmpOdp += tmpA[i];
}
odpowiedz = tmpOdp;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(ll i=1; i<=n; i++)
{
cin >> A[i] >> B[i];
if(B[i] != -1) I++;
else B[i] = dupsko;
tab.push_back({A[i], B[i]});
}
I = min(I, k);
sort(tab.begin(), tab.end(), cmpB);
/*cout << "tab\n";
for(pii v : tab) cout << v.f << "," << v.s << " ";
cout << endl;*/
ustal_odp();
for(ll i=1; i<=n; i++)
{
if(tab[i].s == dupsko)
{
kosztB[1][i] = dupsko/2;
sumaA[1][i] = dupsko/2;
continue;
}
for(ll j=1; j<=n; j++)
{
ciagA[1][i].push_back(j);
}
ciagA[1][i].push_back(0);
sort(ciagA[1][i].begin(), ciagA[1][i].end(), cmpA);
ll tmpS = ciagA[1][i].size();
for(ll j=1; j<tmpS; j++)
{
if(ciagA[1][i][j] == i)
{
ciagA[1][i].erase(ciagA[1][i].begin() + j);
break;
}
}
maxA[1][i] = ciagA[1][i][k-1];
for(ll j=1; j<=k-1; j++) sumaA[1][i] += tab[ciagA[1][i][j]].f;
kosztB[1][i] = (ld) tab[i].s;
odpowiedz = min(odpowiedz, kosztB[1][i] + (ld) ((ld) sumaA[1][i] /(ld) 2));
/*cout << "dla " << 1 << ", " << i << ":\n";
cout << sumaA[1][i] << " " << fixed << setprecision(2) << kosztB[1][i] << " " << maxA[1][i] << " {";
for(ll v : ciagA[1][i]) cout << v << ",";
cout << "} oraz wyn = " << fixed << setprecision(3) << kosztB[1][i] + (ld) ((ld) sumaA[1][i] /(ld) 2) << endl;*/
}
for(ll i=2; i<=I; i++)
{
for(ll j=1; j<=n; j++)
{
if(tab[j].s == dupsko)
{
kosztB[i][j] = (ld) dupsko;
sumaA[i][j] = (ld) dupsko;
continue;
}
ld minWynik = 10000000;
ll ktoMinWynik = -1;
for(ll o=1; o<j; o++)
{
if(kosztB[i-1][o] == dupsko) continue;
ld tmpWynik = kosztB[i-1][o] + (ld) ((ld) sumaA[i-1][o] /(ld) (i+1));
if(tab[maxA[i-1][o]].f >= tab[j].f)
{
tmpWynik -= (ld) tab[j].f /(ld) (i+1);
}
else
{
tmpWynik -= (ld) tab[maxA[i-1][o]].f / (ld) (i+1);
}
if(tmpWynik < minWynik)
{
minWynik = tmpWynik;
ktoMinWynik = o;
}
}
if(ktoMinWynik == -1)
{
kosztB[i][j] = (ld) dupsko;
sumaA[i][j] = (ld) dupsko;
continue;
}
kosztB[i][j] = kosztB[i-1][ktoMinWynik] + (ld)((ld)tab[j].s / (ld)i);
ciagA[i][j] = ciagA[i-1][ktoMinWynik];
ll tmpS = ciagA[i][j].size();
for(ll o=1; o<tmpS; o++)
{
if(ciagA[i][j][o] == j)
{
ciagA[i][j].erase(ciagA[i][j].begin() + o);
break;
}
}
for(ll o=1; o<=k-i; o++)
{
sumaA[i][j] += tab[ciagA[i][j][o]].f;
}
maxA[i][j] = ciagA[i][j][k-i];
odpowiedz = min(odpowiedz, kosztB[i][j] + (ld) ((ld) sumaA[i][j] /(ld) (i+1)));
/*cout << "dla " << i << ", " << j << ":\n";
cout << sumaA[i][j] << " " << fixed << setprecision(2) << kosztB[i][j] << " " << maxA[i][j] << " {";
for(ll v : ciagA[i][j]) cout << v << ",";
cout << "} oraz wyn = " << fixed << setprecision(3) << kosztB[i][j] + (ld) ((ld) sumaA[i][j] /(ld) (i+1)) << endl;*/
}
}
/*cout << "ciagA:\n";
for(ll i=1; i<=I; i++)
{
for(ll j=1; j<=n; j++)
{
cout << "{";
for(ll v : ciagA[i][j]) cout << v << ",";
cout << "} ";
}
cout << endl;
}*/
cout << fixed << setprecision(7) << odpowiedz;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
352 ms |
230908 KB |
Output is correct |
13 |
Correct |
174 ms |
129840 KB |
Output is correct |
14 |
Correct |
29 ms |
33112 KB |
Output is correct |
15 |
Correct |
547 ms |
335824 KB |
Output is correct |
16 |
Correct |
218 ms |
152320 KB |
Output is correct |
17 |
Correct |
27 ms |
32188 KB |
Output is correct |
18 |
Correct |
377 ms |
345964 KB |
Output is correct |
19 |
Correct |
235 ms |
159824 KB |
Output is correct |
20 |
Correct |
26 ms |
30276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12768 KB |
Output is correct |
3 |
Correct |
2 ms |
12712 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12636 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
12636 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12768 KB |
Output is correct |
3 |
Correct |
2 ms |
12712 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12636 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
12636 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
12636 KB |
Output is correct |
16 |
Correct |
2 ms |
12636 KB |
Output is correct |
17 |
Correct |
2 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
2 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12892 KB |
Output is correct |
25 |
Correct |
2 ms |
12892 KB |
Output is correct |
26 |
Correct |
2 ms |
12776 KB |
Output is correct |
27 |
Correct |
2 ms |
12636 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12768 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
12636 KB |
Output is correct |
32 |
Correct |
2 ms |
12636 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
3 ms |
12636 KB |
Output is correct |
36 |
Correct |
2 ms |
12868 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Incorrect |
3 ms |
12640 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12768 KB |
Output is correct |
3 |
Correct |
2 ms |
12712 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12636 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
12636 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
12636 KB |
Output is correct |
16 |
Correct |
2 ms |
12636 KB |
Output is correct |
17 |
Correct |
2 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
2 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12892 KB |
Output is correct |
25 |
Correct |
2 ms |
12892 KB |
Output is correct |
26 |
Correct |
2 ms |
12776 KB |
Output is correct |
27 |
Correct |
2 ms |
12636 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12768 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
12636 KB |
Output is correct |
32 |
Correct |
2 ms |
12636 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
3 ms |
12636 KB |
Output is correct |
36 |
Correct |
2 ms |
12868 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Incorrect |
3 ms |
12640 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
357 ms |
345940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
352 ms |
230908 KB |
Output is correct |
13 |
Correct |
174 ms |
129840 KB |
Output is correct |
14 |
Correct |
29 ms |
33112 KB |
Output is correct |
15 |
Correct |
547 ms |
335824 KB |
Output is correct |
16 |
Correct |
218 ms |
152320 KB |
Output is correct |
17 |
Correct |
27 ms |
32188 KB |
Output is correct |
18 |
Correct |
377 ms |
345964 KB |
Output is correct |
19 |
Correct |
235 ms |
159824 KB |
Output is correct |
20 |
Correct |
26 ms |
30276 KB |
Output is correct |
21 |
Correct |
2 ms |
12636 KB |
Output is correct |
22 |
Correct |
2 ms |
12768 KB |
Output is correct |
23 |
Correct |
2 ms |
12712 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
2 ms |
12636 KB |
Output is correct |
26 |
Correct |
2 ms |
12636 KB |
Output is correct |
27 |
Correct |
2 ms |
12636 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
12636 KB |
Output is correct |
32 |
Correct |
2 ms |
12636 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12636 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
36 |
Correct |
2 ms |
12636 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Correct |
2 ms |
12632 KB |
Output is correct |
39 |
Correct |
2 ms |
12636 KB |
Output is correct |
40 |
Correct |
2 ms |
12636 KB |
Output is correct |
41 |
Correct |
2 ms |
12632 KB |
Output is correct |
42 |
Correct |
2 ms |
12636 KB |
Output is correct |
43 |
Correct |
2 ms |
12636 KB |
Output is correct |
44 |
Correct |
3 ms |
12892 KB |
Output is correct |
45 |
Correct |
2 ms |
12892 KB |
Output is correct |
46 |
Correct |
2 ms |
12776 KB |
Output is correct |
47 |
Correct |
2 ms |
12636 KB |
Output is correct |
48 |
Correct |
2 ms |
12636 KB |
Output is correct |
49 |
Correct |
2 ms |
12768 KB |
Output is correct |
50 |
Correct |
2 ms |
12636 KB |
Output is correct |
51 |
Correct |
2 ms |
12636 KB |
Output is correct |
52 |
Correct |
2 ms |
12636 KB |
Output is correct |
53 |
Correct |
2 ms |
12636 KB |
Output is correct |
54 |
Correct |
2 ms |
12888 KB |
Output is correct |
55 |
Correct |
3 ms |
12636 KB |
Output is correct |
56 |
Correct |
2 ms |
12868 KB |
Output is correct |
57 |
Correct |
2 ms |
12636 KB |
Output is correct |
58 |
Incorrect |
3 ms |
12640 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |