#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
vector<pair<int,int>> v;
int n,m;
bool check(int mid){
vector<int> need(n,0);
int left = 0; int tot = 0;
for(int i = 0; i<n && tot <= n*m; i++){
int z = max(v[i].first, v[i].second); // a la clase i, estudio o hi vaig
int k = (mid+z-1)/z; // numero de veces que tengo que estudiar o ir
if(k >= m) tot+=m, need[i] = mid-m * z,tot += (need[i] + v[i].second - 1)/v[i].second; // quan em falta per aprobar
else tot+=k; // classes que mhan sobrat
}
return tot<=n*m;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
v.assign(n,{0,0});
for(auto& x : v) cin>>x.first; //a
for(auto& x : v) cin>>x.second; //b
int l = 0; int r = 1e18+6;
while(r > l+1){
int mid = (l+r)/2;
if(check(mid)) l = mid;
else r = mid;
}
cout<<l<<endl;
}
Compilation message
Main.cpp: In function 'bool check(long long int)':
Main.cpp:10:6: warning: unused variable 'left' [-Wunused-variable]
10 | int left = 0; int tot = 0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
48 ms |
3932 KB |
Output is correct |
10 |
Correct |
31 ms |
2652 KB |
Output is correct |
11 |
Correct |
22 ms |
2156 KB |
Output is correct |
12 |
Correct |
20 ms |
1800 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
41 ms |
7476 KB |
Output is correct |
22 |
Correct |
113 ms |
7468 KB |
Output is correct |
23 |
Correct |
119 ms |
7460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
48 ms |
3932 KB |
Output is correct |
10 |
Correct |
31 ms |
2652 KB |
Output is correct |
11 |
Correct |
22 ms |
2156 KB |
Output is correct |
12 |
Correct |
20 ms |
1800 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
41 ms |
7476 KB |
Output is correct |
22 |
Correct |
113 ms |
7468 KB |
Output is correct |
23 |
Correct |
119 ms |
7460 KB |
Output is correct |
24 |
Correct |
29 ms |
1516 KB |
Output is correct |
25 |
Correct |
72 ms |
3408 KB |
Output is correct |
26 |
Correct |
12 ms |
1124 KB |
Output is correct |
27 |
Correct |
84 ms |
7456 KB |
Output is correct |
28 |
Correct |
98 ms |
7468 KB |
Output is correct |
29 |
Correct |
97 ms |
7456 KB |
Output is correct |
30 |
Correct |
123 ms |
7460 KB |
Output is correct |
31 |
Correct |
191 ms |
7464 KB |
Output is correct |
32 |
Correct |
154 ms |
7512 KB |
Output is correct |
33 |
Incorrect |
266 ms |
7460 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |