This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;
const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 505; // PLZ CHK!
int N,K;
pair<double,double> A[MAX];
double D[MAX][MAX];
const double eps=1e-9;
double go(int i, int x, int h) {
if (x==K-h && i-1-x>=h) return 0.0;
if (i>N) return 1e9;
double &ret=D[i][x];
if (ret>-1.0) return ret;
ret=1e9;
if (x<K-h) ret=min(ret, A[i].first/(1.0*(1+h))+go(i+1,x+1,h));
int y=i-1-x;
double t=0.0;
if (y<h) t=A[i].second/(1.0*(1+y));
ret=min(ret, t+go(i+1,x,h));
return ret;
}
int main() {
fio();
cin>>N>>K;
for (int i=1; i<=N; i++) {
cin>>A[i].first>>A[i].second;
if (abs(A[i].second+1.0)<eps) A[i].second=1e6;
}
sort(A+1,A+N+1,[](auto a, auto b){
return a.second<b.second;
});
double ans=1e9;
for (int i=0; i<=K; i++) {
fill_n(&D[0][0],MAX*MAX,-1.0);
// cout<<go(1,0,i)<<endl;
ans=min(ans, go(1,0,i));
}
cout<<fixed; cout.precision(10);
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |