#include <bits/stdc++.h>
namespace IO {
const int DPAIRSIZ = 1 << 10;
char BB[DPAIRSIZ], *SS = BB, *TT = BB;
inline char getcha() {
return SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT) ? EOF : *SS++;
}
template<typename T = int>
inline T read() {
T x = 0;
int fu = 1;
char c = getcha();
while (c > 57 || c < 48) {
if (c == 45) fu = -1;
c = getcha();
}
while (c <= 57 && c >= 48) {
x = x * 10 + c - 48;
c = getcha();
}
x *= fu;
return x;
}
template<typename T>
inline void read(T &x) {
x = 0;
int fu = 1;
char c = getcha();
while (c > 57 || c < 48) {
if (c == 45) fu = -1;
c = getcha();
}
while (c <= 57 && c >= 48) {
x = x * 10 + c - 48;
c = getcha();
}
x *= fu;
}
template<typename T>
inline void read(T *bg, T *ed) { while (bg != ed) read(*bg++); }
inline void read(char &ch) {
ch = getcha();
while (ch <= 32) ch = getcha();
}
inline void read(char *s) {
char ch = getcha();
while (ch <= 32) ch = getcha();
while (ch > 32) *s++ = ch, ch = getcha();
*s = '\0';
}
inline void read(std::string &s) {
char ch = getcha();
while (ch <= 32) ch = getcha();
while (ch > 32) s.push_back(ch), ch = getcha();
}
inline void sread(char *s) {
char ch = getcha();
while (ch < 32) ch = getcha();
while (ch >= 32) *s++ = ch, ch = getcha();
*s = '\0';
}
inline void pread(char *&s) {
char ch = getcha();
while (ch <= 32) ch = getcha();
while (ch > 32) *s++ = ch, ch = getcha();
*s = '\0';
}
inline void spread(char *&s) {
char ch = getcha();
while (ch < 32) ch = getcha();
while (ch >= 32) *s++ = ch, ch = getcha();
*s = '\0';
}
template<typename T, typename ...Args>
inline void read(T &x, Args &...args) {
read(x);
read(args...);
}
char out[DPAIRSIZ], *Out = out;
#define flush() fwrite(out, 1, Out - out, stdout)
inline void putcha(char x) {
*Out++ = x;
if (Out - out >= (DPAIRSIZ)) flush(), Out = out;
}
template<typename T>
inline void fprint(T x) {
if (x < 0) putcha(45), x = -x;
if (x > 9) fprint(x / 10);
putcha(x % 10 + 48);
}
inline void print() { putcha(10); }
template<typename T>
inline void print(T x) {
fprint(x);
putcha(10);
}
inline void print(char *ch) {
while (*ch != '\0') putcha(*(ch++));
putcha(10);
}
inline void put(char *ch) { while (*ch != '\0') putcha(*(ch++)); }
inline void print(const char *ch) {
while (*ch != '\0') putcha(*(ch++));
putcha(10);
}
inline void put(const char *ch) { while (*ch != '\0') putcha(*(ch++)); }
template<typename T, typename ...Args>
inline void print(T x, Args ...args) {
fprint(x);
putcha(32);
print(args...);
}
template<typename ...Args>
inline void print(const char *ch, Args ...args) {
while (*ch != '\0') putcha(*(ch++));
putcha(32);
print(args...);
}
template<typename ...Args>
inline void print(char *ch, Args ...args) {
while (*ch != '\0') putcha(*(ch++));
putcha(32);
print(args...);
}
template<typename T, typename ...Args>
inline void printl(T x, Args ...args) {
fprint(x);
putcha(10);
printl(args...);
}
template<typename ...Args>
inline void printl(const char *ch, Args ...args) {
while (*ch != '\0') putcha(*(ch++));
putcha(10);
printl(args...);
}
template<typename ...Args>
inline void printl(char *ch, Args ...args) {
while (*ch != '\0') putcha(*(ch++));
putcha(10);
printl(args...);
}
template<typename T>
inline void sprint(T x) {
fprint(x);
putcha(32);
}
template<typename T, typename ...Args>
inline void sprint(T x, Args ...args) {
fprint(x);
putcha(32);
sprint(args...);
}
template<typename T>
inline void sprint(T *bg, T *ed) { while (bg != ed) sprint(*bg++); }
template<typename T>
inline void print(T *bg, T *ed) {
while (bg != ed) sprint(*bg++);
putcha(10);
}
template<typename T>
inline void printl(T *bg, T *ed) { while (bg != ed) print(*bg++); }
class AutoFlush {
public:
~AutoFlush() { flush(); }
} __AutoFlush;
} // namespace IO
using namespace IO;
#define vc vector
#define nd node*
#define pnd pair<nd, nd>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vc<pll> vpll;
typedef vc<vll> vvll;
typedef vc<vpll> vvpll;
template<const ll MOD>
struct mod_mul : std::multiplies<const ll> {
ll operator()(const ll a, const ll b) {
return (a * b) % MOD;
}
};
template<typename T>
inline void sort(T &a) {
sort(a.begin(), a.end());
}
template<typename T>
inline void unique(T &a) {
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template<typename T>
inline void reverse(T &a) {
reverse(a.begin(), a.end());
}
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
struct state {
int a, b;
};
int main() {
int n, k;
read(n, k);
vc<state> a(n);
for (auto &i : a) {
read(i.a, i.b);
if (i.b < 0) i.b = 1e9;
}
sort(a.begin(), a.end(), [](const auto &x, const auto &y) {return x.b < y.b;});
ld ans = INF;
for (int sz = 0; sz < k; ++sz) {
vc<vc<ld>> dp(n + 1, vc<ld>((k - sz) + 1, INF));
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int cnt = 0; cnt <= k - sz; ++cnt) {
int done = i - cnt;
if (done < sz) {
dp[i + 1][cnt] = min(dp[i + 1][cnt], dp[i][cnt] + ((ld)a[i].b / (done + 1)));
} else {
dp[i + 1][cnt] = min(dp[i + 1][cnt], dp[i][cnt]);
}
if (cnt + 1 <= k - sz) dp[i + 1][cnt + 1] = min(dp[i + 1][cnt + 1], dp[i][cnt] + (ld)a[i].a / (sz + 1));
}
}
ans = min(ans, dp[n][k - sz]);
}
cout.precision(18);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
11 ms |
704 KB |
Output is correct |
6 |
Correct |
62 ms |
1276 KB |
Output is correct |
7 |
Correct |
250 ms |
2260 KB |
Output is correct |
8 |
Correct |
568 ms |
3260 KB |
Output is correct |
9 |
Correct |
1022 ms |
4232 KB |
Output is correct |
10 |
Correct |
491 ms |
3072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
11 ms |
704 KB |
Output is correct |
6 |
Correct |
62 ms |
1276 KB |
Output is correct |
7 |
Correct |
250 ms |
2260 KB |
Output is correct |
8 |
Correct |
568 ms |
3260 KB |
Output is correct |
9 |
Correct |
1022 ms |
4232 KB |
Output is correct |
10 |
Correct |
491 ms |
3072 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
116 ms |
1492 KB |
Output is correct |
13 |
Correct |
109 ms |
1492 KB |
Output is correct |
14 |
Correct |
104 ms |
1492 KB |
Output is correct |
15 |
Correct |
514 ms |
3072 KB |
Output is correct |
16 |
Correct |
554 ms |
3072 KB |
Output is correct |
17 |
Correct |
506 ms |
3072 KB |
Output is correct |
18 |
Correct |
1072 ms |
4248 KB |
Output is correct |
19 |
Correct |
1054 ms |
4228 KB |
Output is correct |
20 |
Correct |
1055 ms |
4228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
2 ms |
468 KB |
Output is correct |
47 |
Correct |
4 ms |
548 KB |
Output is correct |
48 |
Correct |
4 ms |
468 KB |
Output is correct |
49 |
Correct |
5 ms |
456 KB |
Output is correct |
50 |
Correct |
5 ms |
456 KB |
Output is correct |
51 |
Correct |
7 ms |
548 KB |
Output is correct |
52 |
Correct |
8 ms |
472 KB |
Output is correct |
53 |
Correct |
3 ms |
468 KB |
Output is correct |
54 |
Correct |
4 ms |
468 KB |
Output is correct |
55 |
Correct |
4 ms |
468 KB |
Output is correct |
56 |
Correct |
3 ms |
468 KB |
Output is correct |
57 |
Correct |
3 ms |
468 KB |
Output is correct |
58 |
Correct |
5 ms |
468 KB |
Output is correct |
59 |
Correct |
4 ms |
468 KB |
Output is correct |
60 |
Correct |
4 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1056 ms |
4256 KB |
Output is correct |
2 |
Correct |
1016 ms |
4224 KB |
Output is correct |
3 |
Correct |
1039 ms |
4244 KB |
Output is correct |
4 |
Correct |
1039 ms |
4264 KB |
Output is correct |
5 |
Correct |
1016 ms |
4228 KB |
Output is correct |
6 |
Correct |
1033 ms |
4260 KB |
Output is correct |
7 |
Correct |
1051 ms |
4232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
11 ms |
704 KB |
Output is correct |
6 |
Correct |
62 ms |
1276 KB |
Output is correct |
7 |
Correct |
250 ms |
2260 KB |
Output is correct |
8 |
Correct |
568 ms |
3260 KB |
Output is correct |
9 |
Correct |
1022 ms |
4232 KB |
Output is correct |
10 |
Correct |
491 ms |
3072 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
116 ms |
1492 KB |
Output is correct |
13 |
Correct |
109 ms |
1492 KB |
Output is correct |
14 |
Correct |
104 ms |
1492 KB |
Output is correct |
15 |
Correct |
514 ms |
3072 KB |
Output is correct |
16 |
Correct |
554 ms |
3072 KB |
Output is correct |
17 |
Correct |
506 ms |
3072 KB |
Output is correct |
18 |
Correct |
1072 ms |
4248 KB |
Output is correct |
19 |
Correct |
1054 ms |
4228 KB |
Output is correct |
20 |
Correct |
1055 ms |
4228 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
2 ms |
340 KB |
Output is correct |
66 |
Correct |
2 ms |
468 KB |
Output is correct |
67 |
Correct |
4 ms |
548 KB |
Output is correct |
68 |
Correct |
4 ms |
468 KB |
Output is correct |
69 |
Correct |
5 ms |
456 KB |
Output is correct |
70 |
Correct |
5 ms |
456 KB |
Output is correct |
71 |
Correct |
7 ms |
548 KB |
Output is correct |
72 |
Correct |
8 ms |
472 KB |
Output is correct |
73 |
Correct |
3 ms |
468 KB |
Output is correct |
74 |
Correct |
4 ms |
468 KB |
Output is correct |
75 |
Correct |
4 ms |
468 KB |
Output is correct |
76 |
Correct |
3 ms |
468 KB |
Output is correct |
77 |
Correct |
3 ms |
468 KB |
Output is correct |
78 |
Correct |
5 ms |
468 KB |
Output is correct |
79 |
Correct |
4 ms |
468 KB |
Output is correct |
80 |
Correct |
4 ms |
436 KB |
Output is correct |
81 |
Correct |
1056 ms |
4256 KB |
Output is correct |
82 |
Correct |
1016 ms |
4224 KB |
Output is correct |
83 |
Correct |
1039 ms |
4244 KB |
Output is correct |
84 |
Correct |
1039 ms |
4264 KB |
Output is correct |
85 |
Correct |
1016 ms |
4228 KB |
Output is correct |
86 |
Correct |
1033 ms |
4260 KB |
Output is correct |
87 |
Correct |
1051 ms |
4232 KB |
Output is correct |
88 |
Correct |
12 ms |
724 KB |
Output is correct |
89 |
Correct |
11 ms |
724 KB |
Output is correct |
90 |
Correct |
64 ms |
1276 KB |
Output is correct |
91 |
Correct |
64 ms |
1276 KB |
Output is correct |
92 |
Correct |
277 ms |
2304 KB |
Output is correct |
93 |
Correct |
259 ms |
2260 KB |
Output is correct |
94 |
Correct |
561 ms |
3260 KB |
Output is correct |
95 |
Correct |
620 ms |
3260 KB |
Output is correct |
96 |
Correct |
831 ms |
3860 KB |
Output is correct |
97 |
Correct |
861 ms |
3840 KB |
Output is correct |
98 |
Correct |
499 ms |
3072 KB |
Output is correct |
99 |
Correct |
483 ms |
3072 KB |
Output is correct |
100 |
Correct |
548 ms |
3072 KB |
Output is correct |
101 |
Correct |
487 ms |
3072 KB |
Output is correct |
102 |
Correct |
481 ms |
3136 KB |
Output is correct |
103 |
Correct |
498 ms |
3072 KB |
Output is correct |
104 |
Correct |
490 ms |
3072 KB |
Output is correct |
105 |
Correct |
499 ms |
3072 KB |
Output is correct |