This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long long ll;
#define int long long
#define sz(x) (int)(x.size())
#define debug(x) cerr << (#x) << ": " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int calc(int a) {
return a/2+a%2;
}
int n, T;
vector<int> a;
string s;
void solve() {
cin >> n >> T;
a.resize(n);
for (auto &u: a) cin >> u;
if (n==2) {
a[0]%=T, a[1]%=T;
int act=calc(abs(a[0]-a[1]));
act=min(act, calc(abs((a[0]+T)-a[1])));
act=min(act, calc(abs(a[0]-(a[1]+T))));
cout << act << endl;
return;
}
int ans=LLONG_MAX;
for (int t=0; t<2*T; t++) {
int tot=0;
for (int i=0; i<n; i++) {
int act=abs(t-a[i]%T);
act=min(act, abs(t-(a[i]%T+T)));
tot=max(tot, act);
}
ans=min(ans, tot);
}
cout << ans << endl;
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;// cin >> tt;
while(tt--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |