#include <iostream>
#include <vector>
int main()
{
using LL = long long;
int n,m; // 1 <= n,m <= 200000
std::vector<LL> t;
// LL x;
std::vector<int> d;
// int y;
std::cin >> n >> m;
t.reserve(n);
d.reserve(m);
for(int i = 0; i < n; ++i)
{
LL x;
std::cin >> x;
t.push_back(x);
}
for (int i = 0; i < m; ++i)
{
int y;
std::cin >> y;
d.push_back(y);
}
for (int y : d)
{
LL m = 0;
LL w = 0;
for (LL x : t)
{
m = std::max(m, x - y);
m += y;
w += m - x;
}
std::cout << w << "\n";
}
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 38 39 40 41 42 43 44 45 | #include <iostream> #include <vector> int main() { using LL = long long; int n,m; // 1 <= n,m <= 200000 std::vector<LL> t; // LL x; std::vector<int> d; // int y; std::cin >> n >> m; t.reserve(n); d.reserve(m); for(int i = 0; i < n; ++i) { LL x; std::cin >> x; t.push_back(x); } for (int i = 0; i < m; ++i) { int y; std::cin >> y; d.push_back(y); } for (int y : d) { LL m = 0; LL w = 0; for (LL x : t) { m = std::max(m, x - y); m += y; w += m - x; } std::cout << w << "\n"; } return 0; } |
English