Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- using namespace std;
- pair<bool, int> hs(vector<int>& a, int t) {
- for (int i = 0; i < a.size(); ++i) {
- if (a[i] == t) {
- for (int j = 0; j < i; ++j) {
- if (a[j] < t) {
- return make_pair(true, a[j]);
- }
- }
- }
- }
- return make_pair(false,-1);
- }
- pair<bool, int> hg(vector<int>& a, int t) {
- for (int i = 0; i < a.size(); ++i) {
- if (a[i] == t) {
- for (int j = i + 1; j < a.size(); ++j) {
- if (a[j] > t) {
- return make_pair(true,a[j]);
- }
- }
- }
- }
- return make_pair(false,-1);
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int t;
- cin>>t;
- while(t--){
- int n;
- cin>>n;
- vector<int> a(n),b(n),c(n);
- string x;
- int m5 = 0;
- for(int i=0;i<n;i++){
- cin>>a[i];
- }
- cin>>x;
- bool v = true;
- for(int i =0;i<n;i++){
- if(x[i]=='1'){
- if(hs(a,a[i]).first&&hg(a,a[i]).first){
- b[m5] = hs(a,a[i]).second;
- c[m5] = hg(a,a[i]).second;
- m5++;
- }
- else{
- v = false;
- break;
- }
- }
- }
- if(v&&(m5<6)){
- cout<<m5<<endl;
- for(int i=0;i<m5;i++){
- cout<<b[i]<<" "<<c[i]<<endl;
- }
- }
- else{
- cout<<"-1"<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment