#include <bits/stdc++.h>
using namespace std;
bool vis[505];
int n, k;
int as, bs;
vector<pair<int, int>> a, b;
int todo=0,ptr=0;
long double cans=1e18, ans = 1e18, csum = 0;
vector<int> vec;
int av[1005], bv[1005];
int main() {
srand(time(NULL));
cin >> n >> k;
for(int i=0;i<n;i++) {
cin >> as >> bs; av[i] = as; bv[i] = bs;
a.emplace_back(as, i);
if(bs!=-1) b.emplace_back(bs, i);
vec.push_back(i);
}
sort(vec.begin(), vec.end(), [&](int i, int j){
if(bv[i] == -1) return (bool)0;
if(bv[j] == -1) return (bool)1;
if(bv[i]-av[i] == bv[j]-av[j]) return av[i] > av[j];
return bv[j]-av[i] > bv[j]-av[j];
});
//blablbalbllba
sort(b.begin(), b.end());
for(int K=0;K<5000;K++) {
ans = 1e18; csum = 0;
sort(a.begin(), a.end());
for(int selb=0;selb<=b.size();selb++) {
vector<bool> vis(n, 0);
todo = k; csum = 0; ptr = 0;
bool broke = 0;
for(int i=0;i<selb;i++) {
if(b[i].first == INT_MAX) broke = 1;
vis[b[i].second] = 1;
csum += 1.00*b[i].first/(i+1); todo--;
}
if(broke) break;
while(ptr<n&&todo > 0){
if(vis[a[ptr].second]){ptr++; continue;}
csum += 1.00*a[ptr].first/(selb+1);
todo--; ptr++;
}
if(todo<=0) ans = min(ans, csum);
}
cans = min(cans, ans);
random_shuffle(b.begin(), b.end());
}
cout << cans;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:34:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int selb=0;selb<=b.size();selb++) {
| ~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
21 ms |
312 KB |
Output is correct |
6 |
Correct |
22 ms |
312 KB |
Output is correct |
7 |
Correct |
23 ms |
212 KB |
Output is correct |
8 |
Correct |
23 ms |
308 KB |
Output is correct |
9 |
Correct |
25 ms |
212 KB |
Output is correct |
10 |
Correct |
35 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
21 ms |
312 KB |
Output is correct |
6 |
Correct |
22 ms |
312 KB |
Output is correct |
7 |
Correct |
23 ms |
212 KB |
Output is correct |
8 |
Correct |
23 ms |
308 KB |
Output is correct |
9 |
Correct |
25 ms |
212 KB |
Output is correct |
10 |
Correct |
35 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1220 ms |
304 KB |
Output is correct |
13 |
Correct |
559 ms |
212 KB |
Output is correct |
14 |
Correct |
180 ms |
212 KB |
Output is correct |
15 |
Correct |
1915 ms |
296 KB |
Output is correct |
16 |
Correct |
1149 ms |
296 KB |
Output is correct |
17 |
Correct |
382 ms |
288 KB |
Output is correct |
18 |
Execution timed out |
2591 ms |
212 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
312 KB |
Output is correct |
16 |
Correct |
6 ms |
300 KB |
Output is correct |
17 |
Correct |
7 ms |
304 KB |
Output is correct |
18 |
Correct |
9 ms |
304 KB |
Output is correct |
19 |
Correct |
9 ms |
212 KB |
Output is correct |
20 |
Incorrect |
8 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
312 KB |
Output is correct |
16 |
Correct |
6 ms |
300 KB |
Output is correct |
17 |
Correct |
7 ms |
304 KB |
Output is correct |
18 |
Correct |
9 ms |
304 KB |
Output is correct |
19 |
Correct |
9 ms |
212 KB |
Output is correct |
20 |
Incorrect |
8 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2547 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
21 ms |
312 KB |
Output is correct |
6 |
Correct |
22 ms |
312 KB |
Output is correct |
7 |
Correct |
23 ms |
212 KB |
Output is correct |
8 |
Correct |
23 ms |
308 KB |
Output is correct |
9 |
Correct |
25 ms |
212 KB |
Output is correct |
10 |
Correct |
35 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1220 ms |
304 KB |
Output is correct |
13 |
Correct |
559 ms |
212 KB |
Output is correct |
14 |
Correct |
180 ms |
212 KB |
Output is correct |
15 |
Correct |
1915 ms |
296 KB |
Output is correct |
16 |
Correct |
1149 ms |
296 KB |
Output is correct |
17 |
Correct |
382 ms |
288 KB |
Output is correct |
18 |
Execution timed out |
2591 ms |
212 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |