Codeforces Round 870 (Div. 2) 1826A - Trust Nobody Solution
Problem Link : https://codeforces.com/problemset/problem/1826/A
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- int a[n+1] ;
- for ( int i = 0 ; i < n ; i++){
- cin >> a[i] ;
- }
- int ans = -1 ;
- for ( int k = 0 ; k < n ; k ++) {
- int cnt = 0 ;
- for ( int i = 0 ; i < n ; i++){
- if (a[i] > k ) cnt ++ ;
- }
- if ( cnt == k ){
- ans = k ;
- break ;
- }
- }
- cout << ans << "\n" ;
- }
- return 0 ;
- }
No comments