//
// main.cpp
// Zapiekanki 2 [B]
//
// Created by Jędrzej Dudzicz on 22.11.2017.
// Copyright © 2017 Jędrzej Dudzicz. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
long long t[1000005];
int d;
int n,m;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
scanf("%lld",&t[i]);
}
for(int q=0;q<m;q++){
scanf("%d",&d);
long long wynik=0,pot=0;
for(int i=0;i<n;i++){
if(pot<t[i]-d+1){
pot=t[i];
}
else {
wynik+=d-(t[i]-pot);
pot+=d;
}
}
printf("%lld\n",wynik);
}
return 0;
}
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 | // // main.cpp // Zapiekanki 2 [B] // // Created by Jędrzej Dudzicz on 22.11.2017. // Copyright © 2017 Jędrzej Dudzicz. All rights reserved. // #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; long long t[1000005]; int d; int n,m; int main(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++){ scanf("%lld",&t[i]); } for(int q=0;q<m;q++){ scanf("%d",&d); long long wynik=0,pot=0; for(int i=0;i<n;i++){ if(pot<t[i]-d+1){ pot=t[i]; } else { wynik+=d-(t[i]-pot); pot+=d; } } printf("%lld\n",wynik); } return 0; } |
English