Submission #718565

# Submission time Handle Problem Language Result Execution time Memory
718565 2023-04-04T10:20:17 Z vinnipuh01 Self Study (JOI22_ho_t2) C++17
0 / 100
376 ms 5004 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;
		}
	}
//	cout << x << " - " << sum << "\n";
	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 = 3e14;
    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:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 175 ms 5000 KB Output is correct
12 Correct 176 ms 5004 KB Output is correct
13 Correct 172 ms 4996 KB Output is correct
14 Incorrect 333 ms 5000 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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 85 ms 2564 KB Output is correct
10 Correct 58 ms 1876 KB Output is correct
11 Correct 42 ms 1496 KB Output is correct
12 Correct 34 ms 1236 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 5 ms 340 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 376 ms 4996 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 175 ms 5000 KB Output is correct
12 Correct 176 ms 5004 KB Output is correct
13 Correct 172 ms 4996 KB Output is correct
14 Incorrect 333 ms 5000 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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 85 ms 2564 KB Output is correct
10 Correct 58 ms 1876 KB Output is correct
11 Correct 42 ms 1496 KB Output is correct
12 Correct 34 ms 1236 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 5 ms 340 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 376 ms 4996 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 175 ms 5000 KB Output is correct
12 Correct 176 ms 5004 KB Output is correct
13 Correct 172 ms 4996 KB Output is correct
14 Incorrect 333 ms 5000 KB Output isn't correct
15 Halted 0 ms 0 KB -