Submission #718566

# Submission time Handle Problem Language Result Execution time Memory
718566 2023-04-04T10:21:56 Z vinnipuh01 Self Study (JOI22_ho_t2) C++17
100 / 100
390 ms 11460 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 = 1e18;

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 ) {
	__int128 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 = 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: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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 233 ms 4996 KB Output is correct
12 Correct 241 ms 5004 KB Output is correct
13 Correct 251 ms 5004 KB Output is correct
14 Correct 300 ms 5012 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 357 ms 5104 KB Output is correct
17 Correct 267 ms 5108 KB Output is correct
18 Correct 245 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 357 ms 5104 KB Output is correct
3 Correct 267 ms 5108 KB Output is correct
4 Correct 245 ms 5004 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 131 ms 2672 KB Output is correct
14 Correct 82 ms 1876 KB Output is correct
15 Correct 59 ms 1492 KB Output is correct
16 Correct 48 ms 1260 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 7 ms 340 KB Output is correct
23 Correct 6 ms 340 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 233 ms 4996 KB Output is correct
12 Correct 241 ms 5004 KB Output is correct
13 Correct 251 ms 5004 KB Output is correct
14 Correct 300 ms 5012 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 131 ms 2672 KB Output is correct
24 Correct 82 ms 1876 KB Output is correct
25 Correct 59 ms 1492 KB Output is correct
26 Correct 48 ms 1260 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 7 ms 340 KB Output is correct
33 Correct 6 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 357 ms 5104 KB Output is correct
36 Correct 267 ms 5108 KB Output is correct
37 Correct 245 ms 5004 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 324 KB Output is correct
45 Correct 5 ms 468 KB Output is correct
46 Correct 8 ms 648 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 42 ms 2096 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 328 KB Output is correct
51 Correct 5 ms 468 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 119 ms 5520 KB Output is correct
56 Correct 83 ms 3156 KB Output is correct
57 Correct 102 ms 3160 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 131 ms 2672 KB Output is correct
10 Correct 82 ms 1876 KB Output is correct
11 Correct 59 ms 1492 KB Output is correct
12 Correct 48 ms 1260 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 0 ms 212 KB Output is correct
18 Correct 7 ms 340 KB Output is correct
19 Correct 6 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 357 ms 5104 KB Output is correct
22 Correct 267 ms 5108 KB Output is correct
23 Correct 245 ms 5004 KB Output is correct
24 Correct 41 ms 1932 KB Output is correct
25 Correct 112 ms 5116 KB Output is correct
26 Correct 27 ms 1416 KB Output is correct
27 Correct 234 ms 10700 KB Output is correct
28 Correct 239 ms 10704 KB Output is correct
29 Correct 242 ms 10884 KB Output is correct
30 Correct 252 ms 10792 KB Output is correct
31 Correct 244 ms 10796 KB Output is correct
32 Correct 390 ms 6172 KB Output is correct
33 Correct 266 ms 11460 KB Output is correct
34 Correct 377 ms 6176 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 233 ms 4996 KB Output is correct
12 Correct 241 ms 5004 KB Output is correct
13 Correct 251 ms 5004 KB Output is correct
14 Correct 300 ms 5012 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 131 ms 2672 KB Output is correct
24 Correct 82 ms 1876 KB Output is correct
25 Correct 59 ms 1492 KB Output is correct
26 Correct 48 ms 1260 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 7 ms 340 KB Output is correct
33 Correct 6 ms 340 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 5 ms 468 KB Output is correct
42 Correct 8 ms 648 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 42 ms 2096 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 328 KB Output is correct
47 Correct 5 ms 468 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 119 ms 5520 KB Output is correct
52 Correct 83 ms 3156 KB Output is correct
53 Correct 102 ms 3160 KB Output is correct
54 Correct 41 ms 1932 KB Output is correct
55 Correct 112 ms 5116 KB Output is correct
56 Correct 27 ms 1416 KB Output is correct
57 Correct 234 ms 10700 KB Output is correct
58 Correct 239 ms 10704 KB Output is correct
59 Correct 242 ms 10884 KB Output is correct
60 Correct 252 ms 10792 KB Output is correct
61 Correct 244 ms 10796 KB Output is correct
62 Correct 390 ms 6172 KB Output is correct
63 Correct 266 ms 11460 KB Output is correct
64 Correct 377 ms 6176 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 357 ms 5104 KB Output is correct
67 Correct 267 ms 5108 KB Output is correct
68 Correct 245 ms 5004 KB Output is correct
69 Correct 28 ms 1456 KB Output is correct
70 Correct 8 ms 576 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 39 ms 1828 KB Output is correct
73 Correct 9 ms 596 KB Output is correct
74 Correct 2 ms 340 KB Output is correct
75 Correct 276 ms 10804 KB Output is correct
76 Correct 251 ms 10896 KB Output is correct
77 Correct 260 ms 10808 KB Output is correct
78 Correct 267 ms 10876 KB Output is correct
79 Correct 293 ms 10700 KB Output is correct
80 Correct 253 ms 10800 KB Output is correct
81 Correct 241 ms 8944 KB Output is correct
82 Correct 233 ms 8780 KB Output is correct