QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430586 | #7279. Tricks of the Trade | ItamarN | 0 | 1ms | 5724kb | C++14 | 3.1kb | 2024-06-04 00:39:34 | 2024-06-04 00:39:35 |
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+1) {
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;
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)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 <= min(b, (l + mid - 1) / 2); 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, b);
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++) {
if (mid - i + 1 >= k) {
opt = max(opt, { sum - cost,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; i++) {
for (int j = i; j < n; j++) {
in(j);
if (j - i + 1 >= k)ans = max(ans, sum - cost);
}
for (int j = i; j < n; j++) {
er(j);
}
}
cout << ans << "\n";
for (int i = 0; i < n; i++)cout << '0';
//for (int i = 0; i <= (n-1)/2; i++)in(s[i]);
//rec(0, n - 1, 0, n - 1);
}
// 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
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5660kb
input:
5 3 3 5 2 3 6 2 1 5 2 3
output:
-2 00000
result:
wrong answer wrong answer on the first question
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #30:
score: 5
Acceptable Answer
time: 1ms
memory: 5724kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2 00000
result:
points 0.50 first question correct
Test #31:
score: 0
Time Limit Exceeded
input:
250000 2 18 35 29 35 18 610084694 18 35 29 35 18 448867144 18 35 29 35 18 971272498 18 35 29 35 18 890430190 18 35 29 35 18 655685684 18 35 29 35 18 234608237 18 35 29 35 18 894586749 18 35 29 35 18 442195168 18 35 29 35 18 341564617 18 35 29 35 18 985069087 18 35 29 35 18 967546483 18 35 29 35 18 5...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%