-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmin.cpp
More file actions
57 lines (52 loc) · 695 Bytes
/
Copy pathmin.cpp
File metadata and controls
57 lines (52 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
int mi(vector<int> a,int k)
{
sort(a.begin(),a.end());
int tot=a.size()/k;
vector<int> res;
int m;
int d=0;
int start=0;
for(int i=0;i<a.size();i++)
{
if(d==0)
{
start=a[i];
}
d++;
if(d==tot)
{
int v=(((a[i]-1)*(a[i]))/2);
int v1=((start*(start+1))/2);
v=v-v1;
v/=(a[i]-start-1);
start=a[i];
d=0;
res.push_back(v);
}
}
d=0;
int j=0;
int val;
for(int i=0;i<res.size();i++)
{
d++;
val=max(val,abs(res[j]-a[i]));
if(d==tot)
{
d=0;
j++;
}
}
return val;
}
int main()
{
int n,k;
cin>>n>>k;
vector<int> arr(n);
for(int i=0;i<n;i++)cin>>arr[i];
int ans=mi(arr,k);
cout<<ans;
}