Saleh127

codeforces 289B.cpp

Jun 1st, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define pi acos(-1)
  6. int main()
  7. {
  8. ll n,m,d,c,e=0,f,i,j,k,l;
  9. cin>>n>>m>>d;
  10. k=n*m;
  11. ll a[k];
  12. for(i=0;i<k;i++)
  13. {
  14. cin>>a[i];
  15. }
  16. sort(a,a+k);
  17. l=k/2;
  18. for(i=0;i<k;i++)
  19. {
  20. if(abs(a[l]-a[i])%d!=0)
  21. {
  22. printf("-1\n");
  23. return 0;
  24. }
  25. e+=(abs(a[l]-a[i]))/d;
  26. }
  27. cout<<e<<endl;
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment