#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
ll dp[555][555];
int main()
{
int n,K;
cin>>n>>K;
vector<pii>t(n);
vector<ll>a(n),b(n);
for(int i=0;i<n;i++){
cin>>t[i].fi>>t[i].se;
if(t[i].se == -1)t[i].se = 1e9;
swap(t[i].fi,t[i].se);
}
sort(all(t));
for(int i=0;i<n;i++){
a[i] = t[i].se;
b[i] = t[i].fi;
//cout<<a[i]<<" "<<b[i]<<'\n';
a[i] *= 1e9;
b[i] *= 1e9;
}
ll ans = 1e18;
for(int k=0;k<=K;k++){
//cout<<k<<'\n';
for(int i=0;i<n;i++){
for(int j=0;j<=n;j++)dp[i][j] = 1e18;
}
dp[0][1] = a[0]/(k+1);
if(b[0] != -1 && k)dp[0][0] = b[0];
else if(!k)dp[0][0] = 0;
for(int i=1;i<n;i++){
for(int j=0;j<=i+1;j++){
int c = i+1 - j;
if(b[i] != -1 && c<=k && c){ //add coord
dp[i][j] = min(dp[i][j],dp[i-1][j] + b[i]/c);
}
if(j){
dp[i][j] = min(dp[i][j],dp[i-1][j-1] + a[i]/(k+1));
}
if(c>k)dp[i][j] = min(dp[i][j],dp[i-1][j]);
// cout<<dp[i][j]/1e9<<" ";
}
// cout<<'\n';
}
for(int i=K-1;i<n;i++){
for(int j=0;j<=i+1;j++){
int c = min(k,i+1 - j);
if(c == k && c+j >= K)ans = min(ans,dp[i][j]);
}
}
}
ld fin = ans;
fin/=1e9;
cout<<fixed<<setprecision(5)<<fin<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
2488 KB |
Output is correct |
6 |
Correct |
68 ms |
2392 KB |
Output is correct |
7 |
Correct |
165 ms |
2484 KB |
Output is correct |
8 |
Correct |
230 ms |
2396 KB |
Output is correct |
9 |
Correct |
306 ms |
2644 KB |
Output is correct |
10 |
Correct |
203 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
2488 KB |
Output is correct |
6 |
Correct |
68 ms |
2392 KB |
Output is correct |
7 |
Correct |
165 ms |
2484 KB |
Output is correct |
8 |
Correct |
230 ms |
2396 KB |
Output is correct |
9 |
Correct |
306 ms |
2644 KB |
Output is correct |
10 |
Correct |
203 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
84 ms |
2392 KB |
Output is correct |
13 |
Correct |
84 ms |
2608 KB |
Output is correct |
14 |
Correct |
83 ms |
2604 KB |
Output is correct |
15 |
Correct |
215 ms |
2396 KB |
Output is correct |
16 |
Correct |
209 ms |
2396 KB |
Output is correct |
17 |
Correct |
224 ms |
2600 KB |
Output is correct |
18 |
Correct |
293 ms |
2600 KB |
Output is correct |
19 |
Correct |
297 ms |
2396 KB |
Output is correct |
20 |
Correct |
292 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
860 KB |
Output is correct |
42 |
Correct |
1 ms |
860 KB |
Output is correct |
43 |
Correct |
1 ms |
860 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
2 ms |
860 KB |
Output is correct |
46 |
Correct |
3 ms |
860 KB |
Output is correct |
47 |
Correct |
2 ms |
860 KB |
Output is correct |
48 |
Correct |
2 ms |
856 KB |
Output is correct |
49 |
Correct |
2 ms |
860 KB |
Output is correct |
50 |
Correct |
3 ms |
856 KB |
Output is correct |
51 |
Correct |
3 ms |
876 KB |
Output is correct |
52 |
Correct |
3 ms |
856 KB |
Output is correct |
53 |
Correct |
2 ms |
860 KB |
Output is correct |
54 |
Correct |
2 ms |
860 KB |
Output is correct |
55 |
Correct |
2 ms |
860 KB |
Output is correct |
56 |
Correct |
2 ms |
656 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
3 ms |
860 KB |
Output is correct |
59 |
Correct |
2 ms |
860 KB |
Output is correct |
60 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
306 ms |
2604 KB |
Output is correct |
2 |
Correct |
290 ms |
2616 KB |
Output is correct |
3 |
Correct |
274 ms |
2396 KB |
Output is correct |
4 |
Correct |
295 ms |
2640 KB |
Output is correct |
5 |
Correct |
277 ms |
2396 KB |
Output is correct |
6 |
Correct |
313 ms |
2396 KB |
Output is correct |
7 |
Correct |
288 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
2488 KB |
Output is correct |
6 |
Correct |
68 ms |
2392 KB |
Output is correct |
7 |
Correct |
165 ms |
2484 KB |
Output is correct |
8 |
Correct |
230 ms |
2396 KB |
Output is correct |
9 |
Correct |
306 ms |
2644 KB |
Output is correct |
10 |
Correct |
203 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
84 ms |
2392 KB |
Output is correct |
13 |
Correct |
84 ms |
2608 KB |
Output is correct |
14 |
Correct |
83 ms |
2604 KB |
Output is correct |
15 |
Correct |
215 ms |
2396 KB |
Output is correct |
16 |
Correct |
209 ms |
2396 KB |
Output is correct |
17 |
Correct |
224 ms |
2600 KB |
Output is correct |
18 |
Correct |
293 ms |
2600 KB |
Output is correct |
19 |
Correct |
297 ms |
2396 KB |
Output is correct |
20 |
Correct |
292 ms |
2392 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
600 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
860 KB |
Output is correct |
62 |
Correct |
1 ms |
860 KB |
Output is correct |
63 |
Correct |
1 ms |
860 KB |
Output is correct |
64 |
Correct |
1 ms |
860 KB |
Output is correct |
65 |
Correct |
2 ms |
860 KB |
Output is correct |
66 |
Correct |
3 ms |
860 KB |
Output is correct |
67 |
Correct |
2 ms |
860 KB |
Output is correct |
68 |
Correct |
2 ms |
856 KB |
Output is correct |
69 |
Correct |
2 ms |
860 KB |
Output is correct |
70 |
Correct |
3 ms |
856 KB |
Output is correct |
71 |
Correct |
3 ms |
876 KB |
Output is correct |
72 |
Correct |
3 ms |
856 KB |
Output is correct |
73 |
Correct |
2 ms |
860 KB |
Output is correct |
74 |
Correct |
2 ms |
860 KB |
Output is correct |
75 |
Correct |
2 ms |
860 KB |
Output is correct |
76 |
Correct |
2 ms |
656 KB |
Output is correct |
77 |
Correct |
2 ms |
860 KB |
Output is correct |
78 |
Correct |
3 ms |
860 KB |
Output is correct |
79 |
Correct |
2 ms |
860 KB |
Output is correct |
80 |
Correct |
2 ms |
860 KB |
Output is correct |
81 |
Correct |
306 ms |
2604 KB |
Output is correct |
82 |
Correct |
290 ms |
2616 KB |
Output is correct |
83 |
Correct |
274 ms |
2396 KB |
Output is correct |
84 |
Correct |
295 ms |
2640 KB |
Output is correct |
85 |
Correct |
277 ms |
2396 KB |
Output is correct |
86 |
Correct |
313 ms |
2396 KB |
Output is correct |
87 |
Correct |
288 ms |
2392 KB |
Output is correct |
88 |
Correct |
26 ms |
2392 KB |
Output is correct |
89 |
Correct |
26 ms |
2396 KB |
Output is correct |
90 |
Correct |
68 ms |
2396 KB |
Output is correct |
91 |
Correct |
64 ms |
2392 KB |
Output is correct |
92 |
Correct |
151 ms |
2600 KB |
Output is correct |
93 |
Correct |
158 ms |
2608 KB |
Output is correct |
94 |
Correct |
228 ms |
2396 KB |
Output is correct |
95 |
Correct |
227 ms |
2600 KB |
Output is correct |
96 |
Correct |
248 ms |
2392 KB |
Output is correct |
97 |
Correct |
265 ms |
2648 KB |
Output is correct |
98 |
Correct |
212 ms |
2396 KB |
Output is correct |
99 |
Correct |
235 ms |
2392 KB |
Output is correct |
100 |
Correct |
211 ms |
2604 KB |
Output is correct |
101 |
Correct |
204 ms |
2396 KB |
Output is correct |
102 |
Correct |
202 ms |
2392 KB |
Output is correct |
103 |
Correct |
219 ms |
2392 KB |
Output is correct |
104 |
Correct |
206 ms |
2392 KB |
Output is correct |
105 |
Correct |
199 ms |
2392 KB |
Output is correct |