#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 200006 #define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define pii pair<int,int> #define fi first #define se second typedeflonglong ll; int n , m , A[MAXN]; int x , a , y , b; longlong k; intgcd( int a , int b ){ return b ? gcd( b , a % b ) : a; } intlcm( int a , int b ){ return a / gcd( a , b ) * b; } boolcmp( int a , int b ){ return a > b; } boolchk( int r ){ int t = lcm( a , b ); int gd = r / t , X = r / a - gd , Y = r / b - gd; int res = A[gd] / 100 * ( x + y ) + ( A[gd + X] - A[gd] ) / 100 * x + ( A[gd + X + Y] - A[gd + X] ) / 100 * y; return res >= k; } voidsolve( ){ cin >> n; rep( i , 1 , n ) scanf("%lld" , A + i); sort( A + 1 , A + 1 + n , cmp ); for( int i = 1 ; i <= n ; ++ i ) A[i] += A[i - 1]; cin >> x >> a >> y >> b >> k; if( x < y ) swap( x , y ) , swap( a , b ); int l = 0 , r = n , mid; while( l <= r ) { mid = l + r >> 1; if( chk( mid ) ) r = mid - 1; else l = mid + 1; } cout << ( l > n ? -1 : l ) << endl; } signedmain(){ int T;cin >> T;while( T-- ) solve(); }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 300016 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define pii pair<int,int> #define fi first #define se second typedeflonglong ll; int n , m , A[MAXN] , L[MAXN] , R[MAXN] , a[MAXN]; voidsolve( ){ cin >> n; rep( i , 1 , n ) scanf("%d",&A[i]) , a[i] = A[i] , L[i] = R[i] = 0; sort( a + 1 , a + 1 + n ); int sz = unique( a + 1 , a + 1 + n ) - a - 1; for( int i = 1 ; i <= n ; ++ i ) A[i] = lower_bound( a + 1 , a + 1 + sz , A[i] ) - a; for( int i = 1 ; i <= n ; ++ i ) if( !L[A[i]] ) L[A[i]] = i; for( int i = n ; i >= 1 ; -- i ) if( !R[A[i]] ) R[A[i]] = i; int ok = 1 , ok1 = 1; for( int i = 1 ; i <= sz ; ) { int ps = 0; for( int j = i + 1 ; j <= sz ; ++ j ) { if( R[j - 1] > L[j] ) { ps = j - 1; break; } } if( !ps ) ps = sz; ok = max( ok , ps - i + 1 ); i = ps + 1; } cout << sz - ok << endl; } signedmain(){ int T;cin >> T;while( T-- ) solve(); }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 500016 #define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair typedeflonglong ll; int n , k; vector<pii> G[MAXN]; int dp[MAXN][2]; voidwork( int u , int fa , int wfa ){ dp[u][1] = wfa , dp[u][0] = 0; for( auto& t : G[u] ) if( t.se != fa ) { work( t.se , u , t.fi ); t.fi = dp[t.se][1] - dp[t.se][0]; } sort( G[u].rbegin( ) , G[u].rend() ); int kel = 0; for( pii x : G[u] ) { if( x.se == fa ) continue; ++ kel; if( kel < k ) dp[u][1] += max( dp[x.se][1] , dp[x.se][0] ); else dp[u][1] += dp[x.se][0]; if( kel <= k ) dp[u][0] += max( dp[x.se][1] , dp[x.se][0] ); else dp[u][0] += dp[x.se][0]; } } voidsolve( ){ scanf("%lld%lld",&n,&k); rep( i , 1 , n ) G[i].clear(); for( int i = 1 , u , v , w ; i < n ; ++ i ) { scanf("%lld%lld%lld",&u,&v,&w); G[u].emplace_back( mp( w , v ) ); G[v].emplace_back( mp( w , u ) ); } work( 1 , 1 , 0 ); printf("%lld\n",dp[1][0]); } signedmain(){ int T;cin >> T;while( T-- ) solve(); }