#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; typedef long long int LL; typedef unsigned long long int ULL; #define dbg(x) \ { std::cerr << #x << " = " << x << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<LL> tim; vector<LL> times(n); LL b; cin >> b; tim.push_back(b); times[0]++; for (LL i = 1, j = 0; i < n; ++i) { LL a; cin >> a; if(tim[j] != a) { tim.push_back(a); j++; } times[j]++; } vector<LL> ovens(k); for (LL i = 0; i < k; ++i) { cin >> ovens[i]; } for (int i = 0; i < k; ++i) { LL sum = 0; LL rTime = 0; LL cost = 0; for (int j = 0; j < tim.size(); ++j) { LL cost = (ovens[i] * ((times[j] * (times[j] + 1)) >> 1)); if (rTime < tim[j] - ovens[i]) { LL move = cost - times[j] * ovens[i]; rTime = (tim[j] - ovens[i]) + (times[j] * ovens[i]); sum += move; } else { LL move = cost + (times[j] * (rTime - tim[j])); rTime += (times[j] * ovens[i]); sum += move; } } cout << sum << '\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 46 47 48 49 50 51 52 53 54 55 56 57 | #include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; typedef long long int LL; typedef unsigned long long int ULL; #define dbg(x) \ { std::cerr << #x << " = " << x << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<LL> tim; vector<LL> times(n); LL b; cin >> b; tim.push_back(b); times[0]++; for (LL i = 1, j = 0; i < n; ++i) { LL a; cin >> a; if(tim[j] != a) { tim.push_back(a); j++; } times[j]++; } vector<LL> ovens(k); for (LL i = 0; i < k; ++i) { cin >> ovens[i]; } for (int i = 0; i < k; ++i) { LL sum = 0; LL rTime = 0; LL cost = 0; for (int j = 0; j < tim.size(); ++j) { LL cost = (ovens[i] * ((times[j] * (times[j] + 1)) >> 1)); if (rTime < tim[j] - ovens[i]) { LL move = cost - times[j] * ovens[i]; rTime = (tim[j] - ovens[i]) + (times[j] * ovens[i]); sum += move; } else { LL move = cost + (times[j] * (rTime - tim[j])); rTime += (times[j] * ovens[i]); sum += move; } } cout << sum << '\n'; } return 0; } |