Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define ALL(o) (o).begin(),(o).end()
- #define fo(n) for(int i=0;i<n;i++)
- typedef long long LL;
- bool cmp( int a , int b ) { return a > b; }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie();
- int t;
- cin >> t;
- while( t-- ){
- vector<int> a , b;
- int n , tmp;
- cin >> n;
- fo( n ) {
- cin >> tmp;
- if( tmp > 0 ) a.pb( tmp );
- else b.pb( tmp * -1 );
- }
- sort( ALL(a) , cmp );
- sort( ALL(b) , cmp );
- int j = 0 , k = 0 , ans = 1 , now;
- bool p = a[j] > b[k] ? 1 : 0;
- now = a[j] > b[k] ? a[j++] : b[k++];
- if( !k )
- while( k < b.size() )
- if( b[k++] < now ){
- now = b[k - 1] , ++ans , p = 0;
- break;
- }
- while( ( j < a.size() && !p ) || ( k < b.size() && p ) ){
- while( j < a.size() && !p )
- if( a[j++] < now ) {
- now = a[j - 1] , p = 1 , ++ans ;
- break;
- }
- while( k < b.size() && p )
- if( b[k++] < now ) {
- now = b[k - 1] , p = 0 , ++ans ;
- break;
- }
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement