• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codechef November Challenge 2013 Uncle Johny

Uncle Johny

Problem code: JOHNY

  • Submit
  • My Submissions
  • All Submissions
 

Read problems statements in Mandarin Chinese and Russian.

Vlad enjoys listening to music. He lives in Sam's Town. A few days ago he had a birthday, so his parents gave him a gift: MP3-player! Vlad was the happiest man in the world! Now he can listen his favorite songs whenever he wants!

Vlad built up his own playlist. The playlist consists of N songs, each has a unique positive integer length. Vlad likes all the songs from his playlist, but there is a song, which he likes more than the others. It's named "Uncle Johny".

After creation of the playlist, Vlad decided to sort the songs in increasing order of their lengths. For example, if the lengths of the songs in playlist was {1, 3, 5, 2, 4} after sorting it becomes {1, 2, 3, 4, 5}. Before the sorting, "Uncle Johny" was on K-th position (1-indexing is assumed for the playlist) in the playlist.

Vlad needs your help! He gives you all the information of his playlist. Your task is to find the position of "Uncle Johny" in the sorted playlist.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case contains one integer N denoting the number of songs in Vlad's playlist. The second line contains N space-separated integers A1, A2, ..., AN denoting the lenghts of Vlad's songs. The third line contains the only integer K - the position of "Uncle Johny" in the initial playlist.

 

Output

For each test case, output a single line containing the position of "Uncle Johny" in the sorted playlist.

 

Constraints

1 ≤ T ≤ 1000

1 ≤ K ≤ N ≤ 100

1 ≤ Ai ≤ 109

 

Example

Input:
3
4
1 3 4 2
2
5
1 2 3 9 4
5
5
1 2 3 9 4 
1

Output:
3
4
1

 

Explanation

In the example test there are T=3 test cases.

Test case 1

In the first test case N equals to 4, K equals to 2, A equals to {1, 3, 4, 2}. The answer is 3, because {1, 3, 4, 2} -> {1, 2, 3, 4}. A2 now is on the 3-rd position.

Test case 2

In the second test case N equals to 5, K equals to 5, A equals to {1, 2, 3, 9, 4}. The answer is 4, because {1, 2, 3, 9, 4} -> {1, 2, 3, 4, 9}. A5 now is on the 4-th position.

Test case 3

In the third test case N equals to 5, K equals to 1, A equals to {1, 2, 3, 9, 4}. The answer is 1, because {1, 2, 3, 9, 4} -> {1, 2, 3, 4, 9}. A1 stays on the 1-th position.

Note

"Uncle Johny" is a real song performed by The Killers.

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 5005
14 #define ll long long
15 #define INF 0x7fffffff
16 #define eps 1e-8
17 int n,m;
18 int a[maxn];
19 int main(){
20     int t;
21     scanf("%d", &t);
22     while (t--){
23         scanf("%d", &n);
24         for (int i = 0; i < n; i++)scanf("%d", &a[i]);
25         scanf("%d", &m);
26         m = a[m-1];
27         sort(a, a + n);
28         for (int i = 0; i < n; i++)if (a[i] == m){ m = i + 1; break; }
29         printf("%d\n", m);
30     }
31     return 0;
32 }
View Code

 

posted @ 2013-11-01 22:51  HaibaraAi  阅读(483)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3