卡了一个小时,一直 tle 一个点,心态已经炸了。。。
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b)-1; i>=(a); i--)
#define pb push_back
#define mp std::make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long ll;
typedef double db;
mt19937 mrand(random_device{}());
int rnd(int x) {return mrand() % x;}
const ll mod=1000000007;
ll powmod(ll b, ll e, ll md=mod) {ll a=1; b %= md; assert(e>=0); for (;e;e>>=1, b=b*b%md) if(e&1) {a=a*b%md;} return a;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
// head
const int N = 201000;
int n, m, k, a[N], b[N];
int main() {
scanf("%d%d%d", &n, &m, &k);
rep(i,1,n+1) scanf("%d", a + i), b[i] = a[i];
sort(b + 1, b + m + 1);
ll cur = 0;
multiset<int> small, large;
map<int, int> cnts;
rep(i,1,k+1) small.insert(b[i]), cnts[b[i]] += 1, cur += b[i];
rep(i,k+1,m+1) large.insert(b[i]);
auto pop = [&](int x) {
// for (auto x : small) printf("small %d\n", x);
// for (auto x : large) printf("large %d\n", x);
// printf("xx %d\n", x);
if (cnts[x]) {
cur -= x;
cnts[x]--;
small.erase(small.lower_bound(x));
auto b = large.begin();
cur += *b;
small.insert(*b);
cnts[*b] += 1;
large.erase(b);
} else large.erase(large.lower_bound(x));
};
auto push = [&](int x) {
auto rb = prev(small.end());
if (x < *rb) {
small.erase(rb); cur -= *rb; cnts[*rb] -= 1; large.insert(*rb);
small.insert(x); cur += x; cnts[x] += 1;
} else large.insert(x);
};
for (int l = 1, r = m; r <= n; l++, r++) {
printf("%lld ", cur);
if (r == n) break;
pop(a[l]);
push(a[r+1]);
}
puts("");
}