Submission #1115900

# Submission time Handle Problem Language Result Execution time Memory
1115900 2024-11-21T03:41:46 Z TrieTr Self Study (JOI22_ho_t2) C++14
0 / 100
116 ms 9808 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 = 1e15, 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 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2396 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 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 3 ms 2384 KB Output is correct
11 Correct 112 ms 8668 KB Output is correct
12 Correct 116 ms 8668 KB Output is correct
13 Correct 70 ms 8796 KB Output is correct
14 Incorrect 115 ms 8776 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 2384 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 2384 KB Output is correct
9 Correct 38 ms 6616 KB Output is correct
10 Correct 28 ms 6736 KB Output is correct
11 Correct 21 ms 6736 KB Output is correct
12 Correct 17 ms 4688 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 1 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 Correct 3 ms 2384 KB Output is correct
19 Correct 3 ms 2640 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Incorrect 64 ms 9808 KB Output isn't correct
22 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 2384 KB Output is correct
5 Correct 1 ms 2396 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 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 3 ms 2384 KB Output is correct
11 Correct 112 ms 8668 KB Output is correct
12 Correct 116 ms 8668 KB Output is correct
13 Correct 70 ms 8796 KB Output is correct
14 Incorrect 115 ms 8776 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 2384 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 2384 KB Output is correct
9 Correct 38 ms 6616 KB Output is correct
10 Correct 28 ms 6736 KB Output is correct
11 Correct 21 ms 6736 KB Output is correct
12 Correct 17 ms 4688 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 1 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 Correct 3 ms 2384 KB Output is correct
19 Correct 3 ms 2640 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Incorrect 64 ms 9808 KB Output isn't correct
22 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 2384 KB Output is correct
5 Correct 1 ms 2396 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 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 3 ms 2384 KB Output is correct
11 Correct 112 ms 8668 KB Output is correct
12 Correct 116 ms 8668 KB Output is correct
13 Correct 70 ms 8796 KB Output is correct
14 Incorrect 115 ms 8776 KB Output isn't correct
15 Halted 0 ms 0 KB -