Advertisement
pb_jiang

ABC281E WA

Dec 17th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  5. template <typename... Args> void logger(string vars, Args &&... values)
  6. {
  7.     cerr << vars << " = ";
  8.     string delim = "";
  9.     (..., (cerr << delim << values, delim = ", "));
  10.     cerr << endl;
  11. }
  12.  
  13. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  14. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  15. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  16. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  17.  
  18. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  19. using vi = vector<int>;
  20. using ll = long long;
  21. using pii = pair<int, int>;
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.     int n, m, k;
  26.     cin >> n >> m >> k;
  27.     vi a(n);
  28.     for (auto &x : a)
  29.         cin >> x;
  30.  
  31.     multiset<int> ms;
  32.     for (int i = 0; i < m; ++i)
  33.         ms.insert(a[i]);
  34.     ll sum = 0;
  35.     auto top_k = ms.begin();
  36.     for (int i = 0; i < k; ++i)
  37.         sum += *top_k, ++top_k;
  38.     --top_k;
  39.  
  40.     for (int i = m; i < n; ++i) {
  41.         cout << sum << ' ';
  42.         if (*top_k >= a[i - m]) {
  43.             sum -= a[i - m];
  44.             top_k++;
  45.             sum += *top_k;
  46.         }
  47.         ms.erase(a[i - m]);
  48.  
  49.         ms.insert(a[i]);
  50.         if (*top_k > a[i]) {
  51.             sum -= *top_k;
  52.             top_k--;
  53.             sum += a[i];
  54.         }
  55.     }
  56.     cout << sum << endl;
  57.     return 0;
  58. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement