Language : C++(NOTE : Try a few times yourself before moving to the solution)
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
ll n, x;
cin >> n >> x;
ll a[n], Sum = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
Sum += a[i];
}
ll sum = abs(Sum);
int count = 0;
if (sum <= x)
count = 1;
else
{
while (sum >= x)
{
sum -= x;
count++;
}
count++;
}
cout << count << endl;
}
}
No comments:
Post a Comment