Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
- template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
- template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
- template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using vi = vector<int>;
- using ll = long long;
- using pii = pair<int, int>;
- int main(int argc, char **argv)
- {
- int n, m, k;
- cin >> n >> m >> k;
- vi a(n);
- for (auto &x : a)
- cin >> x;
- multiset<int> ms;
- for (int i = 0; i < m; ++i)
- ms.insert(a[i]);
- ll sum = 0;
- auto top_k = ms.begin();
- for (int i = 0; i < k; ++i)
- sum += *top_k, ++top_k;
- --top_k;
- for (int i = m; i < n; ++i) {
- cout << sum << ' ';
- if (*top_k >= a[i - m]) {
- sum -= a[i - m];
- top_k++;
- sum += *top_k;
- }
- ms.erase(a[i - m]);
- ms.insert(a[i]);
- if (*top_k > a[i]) {
- sum -= *top_k;
- top_k--;
- sum += a[i];
- }
- }
- cout << sum << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement