Submission #928568

# Submission time Handle Problem Language Result Execution time Memory
928568 2024-02-16T16:47:49 Z jcelin Self Study (JOI22_ho_t2) C++14
100 / 100
215 ms 15276 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;

#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

ll a[MAXN], b[MAXN], n, m;

bool check(ll x){
	ll ret = n * m;
	for(int i=1; i<=n and ret >= 0; i++){
		ll uzmi = (x + a[i] - 1) / a[i];
		if(uzmi <= m){
			ret -= uzmi;
			continue;
		}
		ret -= m;
		ll nx = x - m * a[i];
		uzmi = (nx + b[i] - 1) / b[i];
		ret -= uzmi;
	}
	return (ret >= 0);
}

void solve(){
	cin >> n >> m;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=1; i<=n; i++){
		cin >> b[i];
		a[i] = max(a[i], b[i]);
	}
	
	ll lo = 2, hi = INF, ret = 1;
	while(lo <= hi){
		ll mid = (lo + hi) / 2;
		if(check(mid)) lo = mid + 1, ret = mid;
		else hi = mid - 1;
	}
	
	cout << ret << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 86 ms 14400 KB Output is correct
12 Correct 84 ms 14416 KB Output is correct
13 Correct 79 ms 12624 KB Output is correct
14 Correct 57 ms 12460 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 27 ms 9980 KB Output is correct
17 Correct 91 ms 15208 KB Output is correct
18 Correct 87 ms 14508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 27 ms 9980 KB Output is correct
3 Correct 91 ms 15208 KB Output is correct
4 Correct 87 ms 14508 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 45 ms 9676 KB Output is correct
14 Correct 30 ms 8540 KB Output is correct
15 Correct 26 ms 8028 KB Output is correct
16 Correct 20 ms 5704 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2512 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 3 ms 2520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 86 ms 14400 KB Output is correct
12 Correct 84 ms 14416 KB Output is correct
13 Correct 79 ms 12624 KB Output is correct
14 Correct 57 ms 12460 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 45 ms 9676 KB Output is correct
24 Correct 30 ms 8540 KB Output is correct
25 Correct 26 ms 8028 KB Output is correct
26 Correct 20 ms 5704 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2512 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 3 ms 2520 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 27 ms 9980 KB Output is correct
36 Correct 91 ms 15208 KB Output is correct
37 Correct 87 ms 14508 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2516 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 4 ms 2756 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 17 ms 5544 KB Output is correct
49 Correct 0 ms 2508 KB Output is correct
50 Correct 1 ms 2392 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 1 ms 2392 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2392 KB Output is correct
55 Correct 46 ms 9656 KB Output is correct
56 Correct 32 ms 8072 KB Output is correct
57 Correct 22 ms 8004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 45 ms 9676 KB Output is correct
10 Correct 30 ms 8540 KB Output is correct
11 Correct 26 ms 8028 KB Output is correct
12 Correct 20 ms 5704 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2512 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 3 ms 2520 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 27 ms 9980 KB Output is correct
22 Correct 91 ms 15208 KB Output is correct
23 Correct 87 ms 14508 KB Output is correct
24 Correct 29 ms 5468 KB Output is correct
25 Correct 70 ms 9296 KB Output is correct
26 Correct 12 ms 5208 KB Output is correct
27 Correct 82 ms 14628 KB Output is correct
28 Correct 92 ms 14624 KB Output is correct
29 Correct 94 ms 14440 KB Output is correct
30 Correct 123 ms 14628 KB Output is correct
31 Correct 189 ms 14620 KB Output is correct
32 Correct 137 ms 10004 KB Output is correct
33 Correct 208 ms 15276 KB Output is correct
34 Correct 148 ms 10000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 86 ms 14400 KB Output is correct
12 Correct 84 ms 14416 KB Output is correct
13 Correct 79 ms 12624 KB Output is correct
14 Correct 57 ms 12460 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 45 ms 9676 KB Output is correct
24 Correct 30 ms 8540 KB Output is correct
25 Correct 26 ms 8028 KB Output is correct
26 Correct 20 ms 5704 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2512 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 3 ms 2520 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2516 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 4 ms 2756 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 17 ms 5544 KB Output is correct
45 Correct 0 ms 2508 KB Output is correct
46 Correct 1 ms 2392 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 1 ms 2392 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2392 KB Output is correct
51 Correct 46 ms 9656 KB Output is correct
52 Correct 32 ms 8072 KB Output is correct
53 Correct 22 ms 8004 KB Output is correct
54 Correct 29 ms 5468 KB Output is correct
55 Correct 70 ms 9296 KB Output is correct
56 Correct 12 ms 5208 KB Output is correct
57 Correct 82 ms 14628 KB Output is correct
58 Correct 92 ms 14624 KB Output is correct
59 Correct 94 ms 14440 KB Output is correct
60 Correct 123 ms 14628 KB Output is correct
61 Correct 189 ms 14620 KB Output is correct
62 Correct 137 ms 10004 KB Output is correct
63 Correct 208 ms 15276 KB Output is correct
64 Correct 148 ms 10000 KB Output is correct
65 Correct 1 ms 2392 KB Output is correct
66 Correct 27 ms 9980 KB Output is correct
67 Correct 91 ms 15208 KB Output is correct
68 Correct 87 ms 14508 KB Output is correct
69 Correct 21 ms 5212 KB Output is correct
70 Correct 6 ms 2652 KB Output is correct
71 Correct 1 ms 2396 KB Output is correct
72 Correct 31 ms 5468 KB Output is correct
73 Correct 7 ms 2652 KB Output is correct
74 Correct 1 ms 2536 KB Output is correct
75 Correct 96 ms 14420 KB Output is correct
76 Correct 116 ms 14620 KB Output is correct
77 Correct 122 ms 14444 KB Output is correct
78 Correct 169 ms 14624 KB Output is correct
79 Correct 211 ms 14632 KB Output is correct
80 Correct 215 ms 14416 KB Output is correct
81 Correct 195 ms 12628 KB Output is correct
82 Correct 194 ms 12640 KB Output is correct