Submission #718559

# Submission time Handle Problem Language Result Execution time Memory
718559 2023-04-04T10:09:03 Z vinnipuh01 Self Study (JOI22_ho_t2) C++17
0 / 100
475 ms 10876 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
#define sqrt sqrtl

using namespace std;

const long long oo = 1000000000000000000;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;


    freopen ( "sum.in", "r", stdin )
*/

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

bool ok( int x ) {
	sum = 0;
	for ( int i = 1; i <= n; i ++ ) {
		num = x / a[ i ];
		if ( x % a[ i ] ) {
			num ++;
		}
		if ( num <= m )
			sum += m - num;
		else {
			pos = ( num - m - 1 ) * a[ i ];
			if ( x % a[ i ] )
				pos += x % a[ i ];
			else
				pos += a[ i ];
			pos = pos / b[ i ] + (bool)( pos % b[ i ] );
			sum -= pos;
		}
	}
	return sum >= 0;
}

main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    cin >> m;
    for ( int i = 1; i <= n; i ++ )
    	cin >> a[ i ];
    for ( int i = 1; i <= n; i ++ ) {
    	cin >> b[ i ];
    	if ( b[ i ] > a[ i ] )
    		a[ i ] = b[ i ];
    }
    int l, r, mid;
    l = 1;
    r = oo;
    while ( r - l > 1 ) {
    	mid = ( l + r ) / 2;
    	if ( ok( mid ) )
    		l = mid;
    	else
    		r = mid - 1;
	}
	if ( ok( r ) )
		l = r;
	cout << l;
}

Compilation message

Main.cpp:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 233 ms 10876 KB Output is correct
12 Correct 231 ms 10792 KB Output is correct
13 Correct 241 ms 8808 KB Output is correct
14 Incorrect 475 ms 8780 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 121 ms 5564 KB Output is correct
10 Correct 77 ms 3740 KB Output is correct
11 Correct 58 ms 2888 KB Output is correct
12 Correct 48 ms 2412 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 9 ms 424 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 233 ms 10876 KB Output is correct
12 Correct 231 ms 10792 KB Output is correct
13 Correct 241 ms 8808 KB Output is correct
14 Incorrect 475 ms 8780 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 121 ms 5564 KB Output is correct
10 Correct 77 ms 3740 KB Output is correct
11 Correct 58 ms 2888 KB Output is correct
12 Correct 48 ms 2412 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 9 ms 424 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 233 ms 10876 KB Output is correct
12 Correct 231 ms 10792 KB Output is correct
13 Correct 241 ms 8808 KB Output is correct
14 Incorrect 475 ms 8780 KB Output isn't correct
15 Halted 0 ms 0 KB -