显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[100001],b[100001],c[100001],cnt=0,n,k;
bool Function(int x,int y)
{
return x>y;
}
int Back(int x)
{
int s2=x%12;
return x-s2+12;
}
int Front(int x)
{
int s2=x%12;
return x-s2;
}
int main()
{
freopen("year.in","r",stdin);
freopen("year.out","w",stdout);
cin>>n>>k;
k--;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+1+n,Function);
for(int i=2;i<=n;i++)
{
int s1=Front(a[i-1]);
int s2=Back(a[i]);
if(s2<s1)
{
b[++cnt]=s1-s2;
}
}
if(a[n]>12)
{
b[++cnt]=Front(a[n]);
}
sort(b+1,b+1+cnt,Function);
int sum=Back(a[1]);
for(int i=1;i<=k;i++)
{
sum-=b[i];
}
cout<<sum<<endl;
return 0;
}