Submission #768083

# Submission time Handle Problem Language Result Execution time Memory
768083 2023-06-27T12:35:33 Z lollipop Self Study (JOI22_ho_t2) C++17
100 / 100
207 ms 11400 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 1000000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int N = 3e5 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;
int a[ N ] , b[ N ] , n , m ; 
int check( int mid ){
	 int lf = m * n ;
	 FOR( i , n ){
	    int nd = 0 , gn = mid  ; 
	    if( a[ i ] * m <= gn ){
	    	nd = m ; 
	    	gn = gn - a[ i ] * m ; 
		}
		else{
			nd = ( gn + a[ i ] - 1 ) / a[ i ] ;
			gn = 0 ; 
		}
		if( gn != 0 ){
			nd = nd + ( gn + b[ i ] - 1 ) / b[ i ] ; 
		}
		lf = lf - nd ; 
		if( lf < 0 ) return -1 ; 
	 }
	 if( lf >= 0 ) return 1 ;
	 return -1 ; 
}
void solve(){
     cin >> n >> m ; 
     FOR( i , n ) cin >> a[ i ] ;
     FOR( i , n ){
     	cin >> b[ i ] ; 
     	a[ i ] = max( a[ i ] , b[ i ] ) ; 
	 }
     int ans = 0 , l = 0 , r = inf ; 
     while( l < r ){
     	int mid = ( l + r ) / 2 ;
     	if( check( mid ) == 1 ){
     		ans = max( ans , mid ) ;
     		l = mid + 1 ; 
		 }
		 else r = mid ; 
	 }
	 if( check( l ) == 1 ) ans = max( ans , l ) ;
	 if( check( r ) == 1 ) ans = max( ans , r ) ;
	 cout << ans << "\n" ;
}
signed main() {
   ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
   int t = 1 ;// cin >> t ;
   while( t -- ){
   	 solve() ;
   }

}




# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 90 ms 6372 KB Output is correct
12 Correct 94 ms 6328 KB Output is correct
13 Correct 69 ms 6392 KB Output is correct
14 Correct 76 ms 6416 KB Output is correct
15 Correct 1 ms 284 KB Output is correct
16 Correct 35 ms 6132 KB Output is correct
17 Correct 91 ms 11400 KB Output is correct
18 Correct 87 ms 10708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 35 ms 6132 KB Output is correct
3 Correct 91 ms 11400 KB Output is correct
4 Correct 87 ms 10708 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 45 ms 4044 KB Output is correct
14 Correct 30 ms 3284 KB Output is correct
15 Correct 27 ms 2892 KB Output is correct
16 Correct 19 ms 2420 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 90 ms 6372 KB Output is correct
12 Correct 94 ms 6328 KB Output is correct
13 Correct 69 ms 6392 KB Output is correct
14 Correct 76 ms 6416 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 45 ms 4044 KB Output is correct
24 Correct 30 ms 3284 KB Output is correct
25 Correct 27 ms 2892 KB Output is correct
26 Correct 19 ms 2420 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 284 KB Output is correct
35 Correct 35 ms 6132 KB Output is correct
36 Correct 91 ms 11400 KB Output is correct
37 Correct 87 ms 10708 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 16 ms 2132 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 1 ms 328 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 43 ms 5456 KB Output is correct
56 Correct 27 ms 3156 KB Output is correct
57 Correct 29 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 45 ms 4044 KB Output is correct
10 Correct 30 ms 3284 KB Output is correct
11 Correct 27 ms 2892 KB Output is correct
12 Correct 19 ms 2420 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 284 KB Output is correct
21 Correct 35 ms 6132 KB Output is correct
22 Correct 91 ms 11400 KB Output is correct
23 Correct 87 ms 10708 KB Output is correct
24 Correct 27 ms 1868 KB Output is correct
25 Correct 65 ms 5020 KB Output is correct
26 Correct 11 ms 1364 KB Output is correct
27 Correct 85 ms 10704 KB Output is correct
28 Correct 91 ms 10816 KB Output is correct
29 Correct 93 ms 10796 KB Output is correct
30 Correct 111 ms 10692 KB Output is correct
31 Correct 184 ms 10796 KB Output is correct
32 Correct 95 ms 6092 KB Output is correct
33 Correct 207 ms 11396 KB Output is correct
34 Correct 94 ms 6148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 90 ms 6372 KB Output is correct
12 Correct 94 ms 6328 KB Output is correct
13 Correct 69 ms 6392 KB Output is correct
14 Correct 76 ms 6416 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 45 ms 4044 KB Output is correct
24 Correct 30 ms 3284 KB Output is correct
25 Correct 27 ms 2892 KB Output is correct
26 Correct 19 ms 2420 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 3 ms 596 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 16 ms 2132 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 1 ms 328 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 43 ms 5456 KB Output is correct
52 Correct 27 ms 3156 KB Output is correct
53 Correct 29 ms 3152 KB Output is correct
54 Correct 27 ms 1868 KB Output is correct
55 Correct 65 ms 5020 KB Output is correct
56 Correct 11 ms 1364 KB Output is correct
57 Correct 85 ms 10704 KB Output is correct
58 Correct 91 ms 10816 KB Output is correct
59 Correct 93 ms 10796 KB Output is correct
60 Correct 111 ms 10692 KB Output is correct
61 Correct 184 ms 10796 KB Output is correct
62 Correct 95 ms 6092 KB Output is correct
63 Correct 207 ms 11396 KB Output is correct
64 Correct 94 ms 6148 KB Output is correct
65 Correct 1 ms 284 KB Output is correct
66 Correct 35 ms 6132 KB Output is correct
67 Correct 91 ms 11400 KB Output is correct
68 Correct 87 ms 10708 KB Output is correct
69 Correct 19 ms 1360 KB Output is correct
70 Correct 5 ms 600 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 29 ms 1920 KB Output is correct
73 Correct 6 ms 572 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 93 ms 10740 KB Output is correct
76 Correct 104 ms 10736 KB Output is correct
77 Correct 111 ms 10708 KB Output is correct
78 Correct 143 ms 10800 KB Output is correct
79 Correct 192 ms 10804 KB Output is correct
80 Correct 203 ms 10800 KB Output is correct
81 Correct 194 ms 8812 KB Output is correct
82 Correct 193 ms 8780 KB Output is correct