Submission #531997

# Submission time Handle Problem Language Result Execution time Memory
531997 2022-03-02T03:11:50 Z Haruto810198 Self Study (JOI22_ho_t2) C++17
100 / 100
252 ms 11456 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())

#define vi vector<int>
#define pii pair<int, int>

#define F first
#define S second

#define pb push_back
#define eb emplace_back
#define mkp make_pair

const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

const int MAX = 300010;

int n, m;
int A[MAX], B[MAX];

bool check(int T){

	int rem = n*m;
	FOR(i, 1, n, 1){
		
		int cost = 0;
		int tmp = T;

		if(A[i] > B[i]){ // use A first
			if(tmp > A[i] * m){ // A -> B
				rem -= m;
				tmp -= A[i] * m;
				cost = (tmp + B[i] - 1) / B[i];
				rem -= cost;
			}
			else{ // A only
				cost = (tmp + A[i] - 1) / A[i];
				rem -= cost;
			}
		}
		else{ // always use B
			cost = (T + B[i] - 1) / B[i];
			rem -= cost;
		}

		if(rem < 0) return 0;
	}

	return 1;

	//cerr<<"check "<<T<<" : rem = "<<rem<<endl;
	//return (rem >= 0);
}

signed main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>m;
	FOR(i, 1, n, 1){
		cin>>A[i];
	}
	FOR(i, 1, n, 1){
		cin>>B[i];
	}

	int L = 0, R = LNF, mid;
	while(L < R){
		mid = (L + R + 1) / 2;
		if(check(mid)) L = mid;
		else R = mid - 1;
	}

	cout<<L<<'\n';
	
	return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 105 ms 10596 KB Output is correct
12 Correct 108 ms 10708 KB Output is correct
13 Correct 87 ms 8840 KB Output is correct
14 Correct 71 ms 8764 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 30 ms 6080 KB Output is correct
17 Correct 112 ms 11456 KB Output is correct
18 Correct 101 ms 10816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 30 ms 6080 KB Output is correct
3 Correct 112 ms 11456 KB Output is correct
4 Correct 101 ms 10816 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 51 ms 5380 KB Output is correct
14 Correct 35 ms 3796 KB Output is correct
15 Correct 25 ms 2880 KB Output is correct
16 Correct 20 ms 2412 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 3 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 105 ms 10596 KB Output is correct
12 Correct 108 ms 10708 KB Output is correct
13 Correct 87 ms 8840 KB Output is correct
14 Correct 71 ms 8764 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 51 ms 5380 KB Output is correct
24 Correct 35 ms 3796 KB Output is correct
25 Correct 25 ms 2880 KB Output is correct
26 Correct 20 ms 2412 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 3 ms 436 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 30 ms 6080 KB Output is correct
36 Correct 112 ms 11456 KB Output is correct
37 Correct 101 ms 10816 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 320 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 4 ms 720 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 18 ms 2124 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 3 ms 404 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 316 KB Output is correct
55 Correct 54 ms 5420 KB Output is correct
56 Correct 32 ms 3032 KB Output is correct
57 Correct 27 ms 3124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 51 ms 5380 KB Output is correct
10 Correct 35 ms 3796 KB Output is correct
11 Correct 25 ms 2880 KB Output is correct
12 Correct 20 ms 2412 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 3 ms 436 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 30 ms 6080 KB Output is correct
22 Correct 112 ms 11456 KB Output is correct
23 Correct 101 ms 10816 KB Output is correct
24 Correct 29 ms 1876 KB Output is correct
25 Correct 70 ms 4948 KB Output is correct
26 Correct 13 ms 1400 KB Output is correct
27 Correct 94 ms 10776 KB Output is correct
28 Correct 102 ms 10692 KB Output is correct
29 Correct 102 ms 10684 KB Output is correct
30 Correct 123 ms 10684 KB Output is correct
31 Correct 210 ms 10744 KB Output is correct
32 Correct 117 ms 6084 KB Output is correct
33 Correct 252 ms 11332 KB Output is correct
34 Correct 118 ms 6084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 105 ms 10596 KB Output is correct
12 Correct 108 ms 10708 KB Output is correct
13 Correct 87 ms 8840 KB Output is correct
14 Correct 71 ms 8764 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 51 ms 5380 KB Output is correct
24 Correct 35 ms 3796 KB Output is correct
25 Correct 25 ms 2880 KB Output is correct
26 Correct 20 ms 2412 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 3 ms 436 KB Output is correct
34 Correct 1 ms 312 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 4 ms 720 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 18 ms 2124 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 3 ms 404 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 1 ms 316 KB Output is correct
51 Correct 54 ms 5420 KB Output is correct
52 Correct 32 ms 3032 KB Output is correct
53 Correct 27 ms 3124 KB Output is correct
54 Correct 29 ms 1876 KB Output is correct
55 Correct 70 ms 4948 KB Output is correct
56 Correct 13 ms 1400 KB Output is correct
57 Correct 94 ms 10776 KB Output is correct
58 Correct 102 ms 10692 KB Output is correct
59 Correct 102 ms 10684 KB Output is correct
60 Correct 123 ms 10684 KB Output is correct
61 Correct 210 ms 10744 KB Output is correct
62 Correct 117 ms 6084 KB Output is correct
63 Correct 252 ms 11332 KB Output is correct
64 Correct 118 ms 6084 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 30 ms 6080 KB Output is correct
67 Correct 112 ms 11456 KB Output is correct
68 Correct 101 ms 10816 KB Output is correct
69 Correct 21 ms 1348 KB Output is correct
70 Correct 6 ms 588 KB Output is correct
71 Correct 1 ms 320 KB Output is correct
72 Correct 32 ms 1768 KB Output is correct
73 Correct 7 ms 584 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 108 ms 10692 KB Output is correct
76 Correct 124 ms 10688 KB Output is correct
77 Correct 124 ms 10660 KB Output is correct
78 Correct 157 ms 10692 KB Output is correct
79 Correct 213 ms 10728 KB Output is correct
80 Correct 222 ms 10756 KB Output is correct
81 Correct 233 ms 8708 KB Output is correct
82 Correct 181 ms 8708 KB Output is correct