Submission #1115896

# Submission time Handle Problem Language Result Execution time Memory
1115896 2024-11-21T03:40:01 Z TrieTr Self Study (JOI22_ho_t2) C++14
0 / 100
135 ms 14412 KB
#include<bits/stdc++.h>
using namespace std;

void local() {
    #define taskname ""
    if (fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
}

#define ll long long
#define int long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}

const int N = 1e6 + 5;

int n, m;
int a[N], b[N];

bool check(ll x) {
	ll cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] > b[i]) {
			ll useA = min(m * 1ll, (x + a[i] - 1 ) / a[i]);
			ll useB = max(0ll, (x - useA * a[i] + b[i] - 1) / b[i]);
			cnt += useA + useB;		}
		else cnt += (x + b[i] - 1) / b[i];
	}
	return cnt <= 1ll * n * m;
}

signed main() {
    fastio; local();
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    ll lo = 1, hi = 1e18, res = 0;
	while(lo <= hi) {
		ll mid = (lo + hi) >> 1;
		if(check(mid)) lo = (res = mid) + 1;
		else hi = mid - 1;
	}
	cout << res;
}

Compilation message

Main.cpp: In function 'void local()':
Main.cpp:7:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 135 ms 14408 KB Output is correct
12 Correct 130 ms 14412 KB Output is correct
13 Correct 77 ms 12624 KB Output is correct
14 Incorrect 131 ms 12628 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2560 KB Output is correct
9 Correct 43 ms 9664 KB Output is correct
10 Correct 30 ms 8528 KB Output is correct
11 Correct 24 ms 8280 KB Output is correct
12 Correct 18 ms 5712 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Incorrect 2 ms 2384 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 135 ms 14408 KB Output is correct
12 Correct 130 ms 14412 KB Output is correct
13 Correct 77 ms 12624 KB Output is correct
14 Incorrect 131 ms 12628 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2560 KB Output is correct
9 Correct 43 ms 9664 KB Output is correct
10 Correct 30 ms 8528 KB Output is correct
11 Correct 24 ms 8280 KB Output is correct
12 Correct 18 ms 5712 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Incorrect 2 ms 2384 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 135 ms 14408 KB Output is correct
12 Correct 130 ms 14412 KB Output is correct
13 Correct 77 ms 12624 KB Output is correct
14 Incorrect 131 ms 12628 KB Output isn't correct
15 Halted 0 ms 0 KB -