Untitled
#include <bits/stdc++.h> #define endl '\n' #define maxn 100005 #define TASK bai1 #define For(i,a,b) for ( int i = a; i <= b; i++ ) #define Ford(i,a,b) for ( int i = a; i >= b; i-- ) #define MOD 100000000000007 using namespace std; int a[maxn],k,n,ans = MOD,ansb = MOD; void inp() { cin >> n >> k; For(i,1,n) cin >> a[i]; sort(a+1,a+n+1); } int Tonga(int x) { int t = 0; For(i,1,n) { while(x < a[i]) x += k; t = t + x - a[i]; } return t; } int Tongb(int x) { int res = -MOD; For(i,1,n) { while(x < a[i]) x += k; res = max(res,x - a[i]); } return res; } void solve() { For(i,0,k-1) { ans = min(ans,Tonga(i)); ansb = min(ansb,Tongb(i)); } cout << ans << endl << ansb; } int main() { ios_base:: sync_with_stdio(0); cin.tie(0); if(fopen("bai1.inp","r")){ freopen("bai1.inp","r",stdin); } inp(); solve(); }
Leave a Comment