QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#33283 | #1880. Nikanor Loves Games | cdw | WA | 5ms | 14012kb | C++20 | 1.5kb | 2022-05-31 09:33:19 | 2022-05-31 09:33:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point {
ll x, y;
};
inline point operator - (const point &a, const point &b) {
return {a.x - b.x, a.y - b.y};
}
inline __int128 operator ^ (const point &a, const point &b) {
return (__int128)a.x * b.y - (__int128)a.y * b.x;
}
int x[1000010];
ll y[1000010];
int a[1000010], b[1000010], w[1000010], n;
point sta[1000010];
int top;
int main() {
scanf("%d", &n);
int cnt = 0;
x[++cnt] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", a + i, b + i, w + i);
x[++cnt] = a[i];
x[++cnt] = b[i];
}
sort(x + 1, x + 1 + cnt);
cnt = unique(x + 1, x + 1 + cnt) - x - 1;
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(x + 1, x + 1 + cnt, a[i]) - x;
b[i] = lower_bound(x + 1, x + 1 + cnt, b[i]) - x;
y[1] -= w[i];
y[a[i]] += w[i];
y[b[i]] += w[i];
}
for (int i = 2; i <= cnt; i++) y[i] += y[i - 1];
for (int i = 1; i <= cnt; i++) {
point cur{x[i], y[i]};
while (top >= 2 && ((cur - sta[top]) ^ (sta[top] - sta[top - 1])) <= 0) top--;
sta[++top] = cur;
}
ll ans = -1e18;
for (int i = 1, j = top; i <= top; i++) {
while (j >= 2 && sta[j - 1].y - 2 * sta[j - 1].x * sta[i].x >= sta[j].y - 2 * sta[j].x * sta[i].x) j--;
ans = max(ans, sta[i].y + sta[j].y - 2 * sta[i].x * sta[j].x);
}
printf("%lld\n", ans * 2);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 14012kb
input:
2 1 4 15 3 5 10
output:
10
result:
wrong answer 1st numbers differ - expected: '2.5000000', found: '10.0000000', error = '3.0000000'