#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<long long,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define STL(i, x) for(auto &i:x) cout << i << " "; cout << "\n";
using namespace std;
long long a[300050], b[300050], as[300050];
ostream& operator<<(ostream &os, pii XXX){
cout << "[" << XXX.ff << ", " << XXX.ss << "]";
}
void db(){
cout << "\n";
}
template<class T, class ...U>
void db(T XXX, U ...YYY){
cout << XXX; db(YYY...);
}
int main(){
long long n, m;
cin >> n >> m;
loop(i,0,n){
cin >> a[i];
}
loop(i,0,n){
cin >> b[i];
}
long long ans = (9e18);
long long op = n * m, now_val;
pii now;
int now_i;
priority_queue<pii, vector<pii>, greater<pii>> pq;
loop(i,0,n){
pq.push(mp(0,i));
}
loop(i,0,op){
now_val = pq.top().ff;
now_i = pq.top().ss;
pq.pop();
if(a[now_i] > b[now_i] && as[now_i] < m){
as[now_i]++;
now_val += a[now_i];
}
else{
now_val += b[now_i];
}
pq.push(mp(now_val, now_i));
}
cout << pq.top().ff << "\n";
return 0;
}
Compilation message
Main.cpp: In function 'std::ostream& operator<<(std::ostream&, std::pair<long long int, int>)':
Main.cpp:15:1: warning: no return statement in function returning non-void [-Wreturn-type]
15 | }
| ^
Main.cpp: In function 'int main()':
Main.cpp:33:15: warning: unused variable 'ans' [-Wunused-variable]
33 | long long ans = (9e18);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
240 ms |
13464 KB |
Output is correct |
12 |
Correct |
240 ms |
13312 KB |
Output is correct |
13 |
Correct |
173 ms |
13240 KB |
Output is correct |
14 |
Correct |
178 ms |
13356 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
102 ms |
13324 KB |
Output is correct |
17 |
Correct |
250 ms |
13304 KB |
Output is correct |
18 |
Correct |
235 ms |
13384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
102 ms |
13324 KB |
Output is correct |
3 |
Correct |
250 ms |
13304 KB |
Output is correct |
4 |
Correct |
235 ms |
13384 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
134 ms |
6804 KB |
Output is correct |
14 |
Correct |
98 ms |
3956 KB |
Output is correct |
15 |
Correct |
75 ms |
3620 KB |
Output is correct |
16 |
Correct |
76 ms |
2372 KB |
Output is correct |
17 |
Correct |
15 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
316 KB |
Output is correct |
19 |
Correct |
6 ms |
212 KB |
Output is correct |
20 |
Correct |
6 ms |
320 KB |
Output is correct |
21 |
Correct |
5 ms |
320 KB |
Output is correct |
22 |
Correct |
22 ms |
596 KB |
Output is correct |
23 |
Correct |
24 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
240 ms |
13464 KB |
Output is correct |
12 |
Correct |
240 ms |
13312 KB |
Output is correct |
13 |
Correct |
173 ms |
13240 KB |
Output is correct |
14 |
Correct |
178 ms |
13356 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
134 ms |
6804 KB |
Output is correct |
24 |
Correct |
98 ms |
3956 KB |
Output is correct |
25 |
Correct |
75 ms |
3620 KB |
Output is correct |
26 |
Correct |
76 ms |
2372 KB |
Output is correct |
27 |
Correct |
15 ms |
340 KB |
Output is correct |
28 |
Correct |
10 ms |
316 KB |
Output is correct |
29 |
Correct |
6 ms |
212 KB |
Output is correct |
30 |
Correct |
6 ms |
320 KB |
Output is correct |
31 |
Correct |
5 ms |
320 KB |
Output is correct |
32 |
Correct |
22 ms |
596 KB |
Output is correct |
33 |
Correct |
24 ms |
596 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
102 ms |
13324 KB |
Output is correct |
36 |
Correct |
250 ms |
13304 KB |
Output is correct |
37 |
Correct |
235 ms |
13384 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
27 ms |
596 KB |
Output is correct |
46 |
Correct |
10 ms |
852 KB |
Output is correct |
47 |
Correct |
5 ms |
340 KB |
Output is correct |
48 |
Correct |
49 ms |
2716 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
20 ms |
212 KB |
Output is correct |
51 |
Correct |
32 ms |
728 KB |
Output is correct |
52 |
Correct |
5 ms |
340 KB |
Output is correct |
53 |
Correct |
10 ms |
320 KB |
Output is correct |
54 |
Correct |
16 ms |
328 KB |
Output is correct |
55 |
Correct |
144 ms |
7124 KB |
Output is correct |
56 |
Correct |
88 ms |
4440 KB |
Output is correct |
57 |
Correct |
74 ms |
4704 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
134 ms |
6804 KB |
Output is correct |
10 |
Correct |
98 ms |
3956 KB |
Output is correct |
11 |
Correct |
75 ms |
3620 KB |
Output is correct |
12 |
Correct |
76 ms |
2372 KB |
Output is correct |
13 |
Correct |
15 ms |
340 KB |
Output is correct |
14 |
Correct |
10 ms |
316 KB |
Output is correct |
15 |
Correct |
6 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
320 KB |
Output is correct |
17 |
Correct |
5 ms |
320 KB |
Output is correct |
18 |
Correct |
22 ms |
596 KB |
Output is correct |
19 |
Correct |
24 ms |
596 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
102 ms |
13324 KB |
Output is correct |
22 |
Correct |
250 ms |
13304 KB |
Output is correct |
23 |
Correct |
235 ms |
13384 KB |
Output is correct |
24 |
Execution timed out |
1087 ms |
2136 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
240 ms |
13464 KB |
Output is correct |
12 |
Correct |
240 ms |
13312 KB |
Output is correct |
13 |
Correct |
173 ms |
13240 KB |
Output is correct |
14 |
Correct |
178 ms |
13356 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
134 ms |
6804 KB |
Output is correct |
24 |
Correct |
98 ms |
3956 KB |
Output is correct |
25 |
Correct |
75 ms |
3620 KB |
Output is correct |
26 |
Correct |
76 ms |
2372 KB |
Output is correct |
27 |
Correct |
15 ms |
340 KB |
Output is correct |
28 |
Correct |
10 ms |
316 KB |
Output is correct |
29 |
Correct |
6 ms |
212 KB |
Output is correct |
30 |
Correct |
6 ms |
320 KB |
Output is correct |
31 |
Correct |
5 ms |
320 KB |
Output is correct |
32 |
Correct |
22 ms |
596 KB |
Output is correct |
33 |
Correct |
24 ms |
596 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 |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
27 ms |
596 KB |
Output is correct |
42 |
Correct |
10 ms |
852 KB |
Output is correct |
43 |
Correct |
5 ms |
340 KB |
Output is correct |
44 |
Correct |
49 ms |
2716 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
20 ms |
212 KB |
Output is correct |
47 |
Correct |
32 ms |
728 KB |
Output is correct |
48 |
Correct |
5 ms |
340 KB |
Output is correct |
49 |
Correct |
10 ms |
320 KB |
Output is correct |
50 |
Correct |
16 ms |
328 KB |
Output is correct |
51 |
Correct |
144 ms |
7124 KB |
Output is correct |
52 |
Correct |
88 ms |
4440 KB |
Output is correct |
53 |
Correct |
74 ms |
4704 KB |
Output is correct |
54 |
Execution timed out |
1087 ms |
2136 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |