#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
long long int error=0;
int a[100010]={};
int m,n,r = 0;
int g(int x){
return x/r;
}
int main(int argc, char *argv[]) {
int i = 0, j = 0, jb = 0, s = 0, count = 0, upperNum = 0;
cin>>n>>m;
r = m/(n + 1);
a[0] = 0;
for(i = 1; i <= n; i++){
cin>>a[i];
}
for(i = 0; i <= n; i++){
if(i == n){
s = m - a[i];
}
else{
s = a[i+1] - a[i];
}
for(j = 0; j < s; j += count){
upperNum = (g(jb + j) + 1) * r;
if(upperNum > jb + s)
upperNum = jb + s;
count = upperNum - jb - j;
error += abs(i - g(jb + j)) * count;
}
jb += s;
}
printf("%lld", error);
return 0;
}
废了老鼻子劲终于100分了,改了又改,还特意去学了STL,也用了&