Submission #936651

# Submission time Handle Problem Language Result Execution time Memory
936651 2024-03-02T12:42:14 Z william950615 Self Study (JOI22_ho_t2) C++14
100 / 100
276 ms 10884 KB
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mkp make_pair
#define PH push
#define PB push_back
#define REP(i,N) for( int i = 0; i < (N); ++i )
#define FOR(i,a,b) for( int i = (a); i <= (b); ++i )
#define ALL(x) begin(x), end(x)
#define MEM(x) memset(x, 0, sizeof(x))

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T>
using V=vector<T>;

void solve() {
	int N, M; cin >> N >> M;
	V<pll> vc(N);
	for( auto &i : vc ) cin >> i.F;
	for( auto &i : vc ) cin >> i.S;
	ll total = 1LL*N*M;

	auto check = [&]( ll val ) {
		__int128 sum = 0;
		for( auto &i : vc ){
			if( i.F > i.S ) {
				ll cnt = (val+i.F-1)/i.F;
				cnt = min( cnt, (ll)M );
				sum += cnt;
				if( cnt*i.F < val ) {
					sum += (val-cnt*i.F+i.S-1)/i.S;
				}
			}
			else {
				sum += (val+i.S-1)/i.S;
			}
		}
		return sum;
	};

	ll l = 0, r = 1e18+3000;
	while( r-l > 1 ) {
		ll m = (l+r)>>1;
		if( check(m)<=total )
			l=m;
		else 
			r=m;
	}
	cout << l << '\n';
}
int main() {
	int T = 1;
#ifdef LOCAL
	freopen( "input.txt", "r", stdin);
	freopen( "output.txt", "w", stdout );
	cin >> T;
#else
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
	while(T--) solve();

}
# 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 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 180 ms 4956 KB Output is correct
12 Correct 185 ms 4956 KB Output is correct
13 Correct 133 ms 4956 KB Output is correct
14 Correct 276 ms 4956 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 182 ms 4952 KB Output is correct
17 Correct 145 ms 4952 KB Output is correct
18 Correct 143 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 182 ms 4952 KB Output is correct
3 Correct 145 ms 4952 KB Output is correct
4 Correct 143 ms 4956 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 72 ms 2904 KB Output is correct
14 Correct 48 ms 1884 KB Output is correct
15 Correct 36 ms 1628 KB Output is correct
16 Correct 29 ms 1372 KB Output is correct
17 Correct 1 ms 572 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 3 ms 536 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 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 180 ms 4956 KB Output is correct
12 Correct 185 ms 4956 KB Output is correct
13 Correct 133 ms 4956 KB Output is correct
14 Correct 276 ms 4956 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 72 ms 2904 KB Output is correct
24 Correct 48 ms 1884 KB Output is correct
25 Correct 36 ms 1628 KB Output is correct
26 Correct 29 ms 1372 KB Output is correct
27 Correct 1 ms 572 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 536 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 182 ms 4952 KB Output is correct
36 Correct 145 ms 4952 KB Output is correct
37 Correct 143 ms 4956 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 4 ms 604 KB Output is correct
46 Correct 6 ms 640 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 32 ms 2140 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 3 ms 628 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 91 ms 5468 KB Output is correct
56 Correct 46 ms 3160 KB Output is correct
57 Correct 90 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 72 ms 2904 KB Output is correct
10 Correct 48 ms 1884 KB Output is correct
11 Correct 36 ms 1628 KB Output is correct
12 Correct 29 ms 1372 KB Output is correct
13 Correct 1 ms 572 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 536 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 182 ms 4952 KB Output is correct
22 Correct 145 ms 4952 KB Output is correct
23 Correct 143 ms 4956 KB Output is correct
24 Correct 29 ms 1116 KB Output is correct
25 Correct 75 ms 2396 KB Output is correct
26 Correct 16 ms 856 KB Output is correct
27 Correct 144 ms 4956 KB Output is correct
28 Correct 145 ms 4956 KB Output is correct
29 Correct 146 ms 4952 KB Output is correct
30 Correct 153 ms 4956 KB Output is correct
31 Correct 194 ms 4952 KB Output is correct
32 Correct 200 ms 4956 KB Output is correct
33 Correct 210 ms 4952 KB Output is correct
34 Correct 200 ms 4956 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 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 180 ms 4956 KB Output is correct
12 Correct 185 ms 4956 KB Output is correct
13 Correct 133 ms 4956 KB Output is correct
14 Correct 276 ms 4956 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 72 ms 2904 KB Output is correct
24 Correct 48 ms 1884 KB Output is correct
25 Correct 36 ms 1628 KB Output is correct
26 Correct 29 ms 1372 KB Output is correct
27 Correct 1 ms 572 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 536 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 4 ms 604 KB Output is correct
42 Correct 6 ms 640 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 32 ms 2140 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 3 ms 628 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 91 ms 5468 KB Output is correct
52 Correct 46 ms 3160 KB Output is correct
53 Correct 90 ms 3164 KB Output is correct
54 Correct 29 ms 1116 KB Output is correct
55 Correct 75 ms 2396 KB Output is correct
56 Correct 16 ms 856 KB Output is correct
57 Correct 144 ms 4956 KB Output is correct
58 Correct 145 ms 4956 KB Output is correct
59 Correct 146 ms 4952 KB Output is correct
60 Correct 153 ms 4956 KB Output is correct
61 Correct 194 ms 4952 KB Output is correct
62 Correct 200 ms 4956 KB Output is correct
63 Correct 210 ms 4952 KB Output is correct
64 Correct 200 ms 4956 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 182 ms 4952 KB Output is correct
67 Correct 145 ms 4952 KB Output is correct
68 Correct 143 ms 4956 KB Output is correct
69 Correct 23 ms 1372 KB Output is correct
70 Correct 6 ms 600 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 31 ms 1748 KB Output is correct
73 Correct 7 ms 600 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 186 ms 10756 KB Output is correct
76 Correct 194 ms 10836 KB Output is correct
77 Correct 189 ms 10756 KB Output is correct
78 Correct 202 ms 10760 KB Output is correct
79 Correct 222 ms 10884 KB Output is correct
80 Correct 213 ms 10884 KB Output is correct
81 Correct 206 ms 9040 KB Output is correct
82 Correct 201 ms 8848 KB Output is correct