Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. //Bismillahir Rahmanir Rahim
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int main()
  5. {
  6.  
  7.  
  8.     int t;
  9.     scanf("%d", &t);
  10.  
  11.     int z;
  12.     for(z = 1; z <= t; z++){
  13.         int n, k;
  14.         scanf("%d %d", &n, &k);
  15.         int i, temp;
  16.         vector<int> vec;
  17.         for(i = 1; i <= n; i++){
  18.             scanf("%d", &temp);
  19.             vec.push_back(temp);
  20.         }
  21.         //code for checking attempts.
  22.         int first, last;
  23.         printf("Case %d:\n", z);
  24.         int ans = 0;
  25.         for(i = 1; i <= k; i++){
  26.             scanf("%d %d",&first, &last);
  27.             vector <int> vec2;
  28.             vec2 = vec;
  29.             int j;
  30.             if(first != last){
  31.                 for(j = first - 1; j < last - 1; j++){
  32.                     if(vec2[j] < vec2[j + 1]){
  33.                         int x;
  34.                         x = vec2[j];
  35.                         vec2[j] = vec2[j+1];
  36.                         vec2[j+1] = x;
  37.                     }
  38.                 }
  39.  
  40.                 ans = vec2[last - 1];
  41.  
  42.             }
  43.             else ans = vec2[first - 1];
  44.             printf("%d\n", ans);
  45.     /*for(it = vec2.begin(); it != vec2.end(); it++){
  46.         cout << *it << endl;
  47.     } */
  48.  
  49.         }
  50.  
  51.  
  52.  
  53.  
  54.     }
  55.  
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement