Untitled

 avatar
user_0483151
plain_text
5 months ago
919 B
2
Indexable
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 100010
#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 1000000000

using namespace std;

int n,k,a[maxn],ch ;

void inp() {
   cin >> n >> k ;
   For(i,1,n) cin >> a[i];
   sort(a + 1, a + n + 1) ;
}

void solve() {
    int mt = MOD, md = MOD ;
    For(doi,0,k - 1) {
        int t = 0, time = doi;
        ch = -MOD;
        For(i,1,n) {
            while( time < a[i] ) time += k ;
            t += ( time - a[i] ) ;
            ch = max(ch,time - a[i]) ;
        }
        md = min(ch,md);
        mt = min(t,mt) ;
    }
    cout << mt << endl ;
    cout << md ;
}

int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);
    if(fopen("bai2.inp","r")){
        freopen("bai2.inp","r",stdin);
    }
    inp();
    solve();
}
Leave a Comment