#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=5e2+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
ll n,k;
pair<ldb,ldb> vt[MAX];
ldb dp[MAX][MAX];
ldb suf[MAX][MAX];
int main() {
speed;
cin>>n>>k;
for (int i=1;i<=n;i++) {
cin>>vt[i].first>>vt[i].second;
if (vt[i].second==-1) vt[i].second=oo;
}
sort(vt+1,vt+n+1,[=](pair<ldb,ldb> a,pair<ldb,ldb> b){
if (a.second==b.second) return a.first>b.first;
return a.second<b.second;
});
memset(suf,0,sizeof(suf));
for (int i=1;i<=k;i++) {
dp[0][i]=oo;
suf[n+1][i]=oo;
}
dp[0][0]=0;
for (int i=1;i<=n;i++) {
dp[i][0]=0;
for (int j=1;j<=k;j++) {
dp[i][j]=min(dp[i-1][j-1]+vt[i].second/j,dp[i-1][j]);
// cout<<dp[i][j]<<" ";
}
// cout<<"\n";
}
suf[n+1][0]=0;
for (int i=n;i>=0;i--) {;
suf[i][0]=0;
for (int j=k;j>=1;j--) {
suf[i][j]=min(suf[i+1][j-1]+vt[i].first,suf[i+1][j]);
// cout<<i<<" "<<j<<" "<<suf[i+1][j-1]+vt[i].first<<" "<<suf[i+1][j]<<" "<<suf[i][j]<<" suf\n";
}
}
ldb ans=oo;
for (int i=0;i<=n;i++) {
for (int j=k;j>=0;j--) {
ans=min(ans,dp[i][j]+suf[i+1][k-j]/(j+1));
// cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<suf[i+1][k-j]<<"\n";
}
// cout<<"\n";
}
cout<<fixed<<setprecision(20)<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
6 ms |
8536 KB |
Output is correct |
9 |
Correct |
5 ms |
8540 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
6 ms |
8536 KB |
Output is correct |
9 |
Correct |
5 ms |
8540 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
8028 KB |
Output is correct |
13 |
Correct |
3 ms |
8024 KB |
Output is correct |
14 |
Correct |
3 ms |
8028 KB |
Output is correct |
15 |
Correct |
5 ms |
8540 KB |
Output is correct |
16 |
Correct |
4 ms |
8540 KB |
Output is correct |
17 |
Correct |
5 ms |
8540 KB |
Output is correct |
18 |
Correct |
5 ms |
8540 KB |
Output is correct |
19 |
Correct |
6 ms |
8540 KB |
Output is correct |
20 |
Correct |
6 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8540 KB |
Output is correct |
8 |
Correct |
6 ms |
8536 KB |
Output is correct |
9 |
Correct |
5 ms |
8540 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
8028 KB |
Output is correct |
13 |
Correct |
3 ms |
8024 KB |
Output is correct |
14 |
Correct |
3 ms |
8028 KB |
Output is correct |
15 |
Correct |
5 ms |
8540 KB |
Output is correct |
16 |
Correct |
4 ms |
8540 KB |
Output is correct |
17 |
Correct |
5 ms |
8540 KB |
Output is correct |
18 |
Correct |
5 ms |
8540 KB |
Output is correct |
19 |
Correct |
6 ms |
8540 KB |
Output is correct |
20 |
Correct |
6 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4696 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |