ACM template
describe
Answer key
Water problem, understand can A, originally planned to write together with other questions, but due to the other several I will write questions to write in detail, so I listed it separately.
code
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 1e9 + 10;
int a[MAXN];
int main(int argc, const char * argv[])
{
int n, k;
while (cin >> n >> k)
{
long long ans = 0;
int minA = INF;
for (int i = 0; i < n; i++)
{
scanf("%d", a + i);
minA = a[i] < minA ? a[i] : minA;
}
int flag = 1;
for (int i = 0; i < n; i++)
{
if ((a[i] - minA) % k)
{
flag = 0;
break;
}
ans += (a[i] - minA) / k;
}
if (flag)
{
cout << ans << '\n';
}
else
{
cout << "-1\n"; }}return 0;
}
Copy the code