#include<bits/stdc++.h>
#define lli long long
#define f first
#define s second
#define mod 1000000007
#define inf 1000000000
#define mp make_pair
#define pb push_back
using namespace std;
const int N=1000009;
const int M=100009;
int t[N];
int main()
{
int n,m;
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++) scanf("%d", &t[i]);
sort(t+1,t+n+1);
while(m--)
{
lli czas,moment=0,wyn=0;
scanf("%lld",&czas);
for(int i=1;i<=n;i++)
{
if(t[i]-moment>=czas) {moment=t[i]; continue;}
moment+=czas;
wyn+=moment-t[i];
//printf("%d ",moment);
}
printf("%lld\n", wyn);
}
}
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 | #include<bits/stdc++.h> #define lli long long #define f first #define s second #define mod 1000000007 #define inf 1000000000 #define mp make_pair #define pb push_back using namespace std; const int N=1000009; const int M=100009; int t[N]; int main() { int n,m; scanf("%d%d", &n, &m); for(int i=1;i<=n;i++) scanf("%d", &t[i]); sort(t+1,t+n+1); while(m--) { lli czas,moment=0,wyn=0; scanf("%lld",&czas); for(int i=1;i<=n;i++) { if(t[i]-moment>=czas) {moment=t[i]; continue;} moment+=czas; wyn+=moment-t[i]; //printf("%d ",moment); } printf("%lld\n", wyn); } } |
English