Educational Codeforces Round 115 (Rated for Div. 2) 1598C. Delete Two Elements Solution



 Problem Link :   https://codeforces.com/contest/1598/problem/C

Solution in C++:

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

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.