1543B - Customising the Track - CodeForces Solution


combinatorics greedy math *900

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    N = int(input())
    A = list(map(int, input().split(" ")))
    S = sum(A)
    print((S%N)*(N-(S%N)))

C++ Code:

#include <bits/stdc++.h>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#define fast cin.tie(0); cin.sync_with_stdio(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define oo (ll)1e9
#define OO (ll)1e18
#define PI acos(-1)
#define LL __int128
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>,rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int MOD = 998244353;
const ld eps = 1e-6;
int tt = 1;
int test;
const int N = 2e5 + 5;
ll a[N];
int n;
void solve()
{
    cin >> n;
    ll sum = 0;
    for(int i = 0 ; i < n ; i++) cin >> a[i] , sum += a[i];
    ll rem = sum % n;
    cout << rem * (n - rem) << '\n';

}
int main()
{
    fast
    cin >> tt;
    while(tt--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

991B - Getting an A
246A - Buggy Sorting
884A - Book Reading
1180A - Alex and a Rhombus
445A - DZY Loves Chessboard
1372A - Omkar and Completion
159D - Palindrome pairs
981B - Businessmen Problems
1668A - Direction Change
1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards
897A - Scarborough Fair
1433B - Yet Another Bookshelf
1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language