#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int n,m;
scanf("%d", &n);
scanf("%d", &m);
int pom1,pom2;
pom1=0;
int tab[200003];
for (int i=0; i<n; i++){
scanf("%d", &pom2);
tab[i]=pom2-pom1;
pom1=pom2;
}
sort(tab,tab+n);
int pref[200003];
pref[0]=tab[0];
for (int i=1; i<n; i++)
pref[i]=pref[i-1]+tab[i];
int d;
for (int j=0; j<m; j++){
scanf("%d", &d);
int *a;
a=lower_bound(tab,tab+n,d);
int poz=a-tab;
int wy=((d*(poz))-pref[poz-1]);
printf("%d\n", wy);
}
}
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 | #include<cstdio> #include<algorithm> #include<vector> using namespace std; int main(){ int n,m; scanf("%d", &n); scanf("%d", &m); int pom1,pom2; pom1=0; int tab[200003]; for (int i=0; i<n; i++){ scanf("%d", &pom2); tab[i]=pom2-pom1; pom1=pom2; } sort(tab,tab+n); int pref[200003]; pref[0]=tab[0]; for (int i=1; i<n; i++) pref[i]=pref[i-1]+tab[i]; int d; for (int j=0; j<m; j++){ scanf("%d", &d); int *a; a=lower_bound(tab,tab+n,d); int poz=a-tab; int wy=((d*(poz))-pref[poz-1]); printf("%d\n", wy); } } |
English