#include <bits/stdc++.h> using namespace std; long long n, m, t[1000005], x, jest, czas; inline void fastscan(long long &liczba) { char c = 0; liczba = 0; while(c < 33) c = getchar_unlocked(); do { liczba = (liczba << 1) + (liczba << 3) + c - '0'; c = getchar_unlocked(); } while(c > 33); } int main() { fastscan(n); fastscan(m); for (int i = 1; i <= n; i++) { fastscan(t[i]); } sort(t+1, t+n+1); for (int i = 1; i <= m; i++) { fastscan(x); jest = czas = 0; for (int j = 1; j <= n; j++) { if (jest+x>t[j]) czas+=jest+x-t[j], jest+=x; else jest = t[j]; } printf("%lld\n", czas); } }
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 | #include <bits/stdc++.h> using namespace std; long long n, m, t[1000005], x, jest, czas; inline void fastscan(long long &liczba) { char c = 0; liczba = 0; while(c < 33) c = getchar_unlocked(); do { liczba = (liczba << 1) + (liczba << 3) + c - '0'; c = getchar_unlocked(); } while(c > 33); } int main() { fastscan(n); fastscan(m); for (int i = 1; i <= n; i++) { fastscan(t[i]); } sort(t+1, t+n+1); for (int i = 1; i <= m; i++) { fastscan(x); jest = czas = 0; for (int j = 1; j <= n; j++) { if (jest+x>t[j]) czas+=jest+x-t[j], jest+=x; else jest = t[j]; } printf("%lld\n", czas); } } |