QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430590#7279. Tricks of the TradeItamarN0 0ms0kbC++142.9kb2024-06-04 01:06:212024-06-04 01:06:23

Judging History

你现在查看的是最新测评结果

  • [2024-06-04 01:06:23]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-06-04 01:06:21]
  • 提交

answer

#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define x first
#define y second
#define pd pair<double,double>

const int siz = 3e5;
ll c[siz];
ll s[siz];

int n,k;
multiset<int>::iterator kth;
ll sum = 0;
multiset<int> mul;
ll ans = -1e18;
ll cost = 0;
void er(ll i) {
	cost -= c[i];
	ll val = s[i];
	if (mul.size() <= k) {

		mul.erase(mul.find(val));
		sum -= val;
		kth = mul.begin();
	}
	else {
		auto it = mul.find(val);
		if (val < *kth || (val == *kth && it != kth)) {
			mul.erase(it);
			return;
		}
		else {
			kth--;
			sum += *kth - val;
			mul.erase(it);
			return;
		}

	}
}
void in(ll i) {
	ll val = s[i];
	cost += c[i];
	if (mul.size() < k) {
		mul.insert(val);
		sum += val;
		kth = mul.begin();
	}
	else {
		mul.insert(val);
		if (*kth > val)return;
		sum += val - *kth;
		kth++;
	}
}
void rec(int l, int r, int a, int b) {
	if (l > r)return;
	int mid = (l + r) / 2;
	int bor = b;
	b = min(mid , b);
	pll opt={-1e18,a};
	for (int i = a; i <= b; i++) {
		if (mid - i + 1 >= k) {
			opt = max(opt, { sum - cost,i });
		}
		er(i);
	}
	ans = max(ans, opt.x);
	if (l == r) {
		for (int i = a; i <= b; i++) {
			in(i);
		}
		return;
	}
	for (int i = mid; i > max(b,(l+mid-1)/2); i--)er(i);
	for (int i = a; i <=min(b, (l + mid-1) / 2);i++)in(i);
	rec(l, mid - 1, a, opt.y);
	for (int i = mid; i > max(b, (l + mid - 1) / 2); i--)in(i);
	for (int i = a; i < opt.y; i++)er(i);

	for (int i = mid+1; i <= (r+ mid+1) / 2; i++)in(i);
	//for (int i = opt.y; i <=b; i++)in(i);
	rec(mid+1, r, opt.y, bor);
	for (int i = mid + 1; i <= (r + mid + 1) / 2; i++)er(i);
	for (int i = opt.y; i <= b; i++)er(i);

	for (int i = a; i <= b; i++) {
		in(i);
	}
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> c[i];
	for (int i = 0; i < n; i++)cin >> s[i];

	for (int i = 0; i <= (n-1)/2; i++)in(i);
	rec(0, n - 1, 0, n - 1);

	cout << ans << "\n";
	for (int i = 0; i < n; i++)cout << '0';
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

5 3
3 5 2 3 6
2 1 5 2 3

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #30:

score: 0
Runtime Error

input:

5 2
1 6 1 5 2
4 1 6 2 4

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%