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++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- ll sum = 0 ;
- int a[n+1] ;
- for ( int i = 0 ; i < n ; i++) {
- cin >> a[i] ;
- sum += a[i] ;
- }
- ll ans = 0 ;
- sum = sum * 2 ;
- map<ll,int>mp ;
- if (sum % n == 0){
- int nav = sum/n ;
- for ( int i = 0 ; i < n ; i++){
- ans +=mp[nav- a[i]] ;
- mp[a[i]]++ ;
- }
- }
- cout << ans <<'\n' ;
- }
- return 0;
- }
No comments