Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-07-25-02.31.10
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll n,m,q,i,l,k;
- cin>>n>>q;
- vector<ll>x(n);
- vector<ll>a(n);
- vector<ll>lds(n,0);
- for(i=0; i<n; i++)
- {
- cin>>x[i];
- }
- for(i=0; i<n; i++) a[i]=1e9;
- for(i=n-1; i>=0; i--)
- {
- k=lower_bound(a.begin(),a.end(),-x[i])-a.begin();
- lds[i]=k+1;
- a[k]=-x[i];
- }
- cout<<"Case "<<cs<<":"<<nl;
- l=*max_element(lds.begin(),lds.end());
- while(q--)
- {
- cin>>m;
- if(m>l) cout<<"Impossible"<<nl;
- else
- {
- ll last=-1e17;
- for(i=0;i<n && m;i++)
- {
- if(lds[i]>=m && last<x[i])
- {
- cout<<x[i]<<" ";
- last=x[i];
- m--;
- }
- }
- cout<<nl;
- }
- }
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement