E. Kolya and Movie Theatre

https://codeforces.com/problemset/problem/1862/E
这题怎么说呢,有思路但是不够简洁

这些我是想到了,但是考虑的因素太多,事实上只需要考虑加入/减去就可,然后记录sum
如代码:

#define _CRT_SECURE_NO_WARNINGS 
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
#define IOS ios::sync_with_stdio(false), cin.tie(0) ,cout.tie(0)
using namespace std;
#define int long long
const int N = 2e5 + 10;

signed main()
{
	IOS;
	int t; cin >> t;
	while (t--)
	{
		priority_queue<int,vector<int>,greater<int>>pq;
		int n; cin >> n;
		int ans = 0;
		int sum = 0;
		int m, d; cin >> m >> d;
		for (int i = 1; i <= n; i++)
		{
			int x; cin >> x;
			if (x > 0) { pq.push(x); sum += x; }
			if (pq.size() > m) {  sum -= pq.top(); pq.pop(); }
			ans = max(ans, sum - i * d);
		}
		cout << ans << '\n';
	}
	return 0;
}

posted on 2024-07-07 10:03  WHUStar  阅读(2)  评论(0编辑  收藏  举报