Codeforces Round 870 (Div. 2) 1826A - Trust Nobody Solution


  

Problem Link :  https://codeforces.com/problemset/problem/1826/A

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ;
  11. cin >> n ;
  12. int a[n+1] ;
  13. for ( int i = 0 ; i < n ; i++){
  14. cin >> a[i] ;
  15. }
  16. int ans = -1 ;
  17. for ( int k = 0 ; k < n ; k ++) {
  18. int cnt = 0 ;
  19. for ( int i = 0 ; i < n ; i++){
  20. if (a[i] > k ) cnt ++ ;
  21. }
  22. if ( cnt == k ){
  23. ans = k ;
  24. break ;
  25. }
  26. }
  27. cout << ans << "\n" ;
  28. }
  29. return 0 ;
  30. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.