QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721221#1880. Nikanor Loves GamesNt_YesterWA 1ms9836kbC++201.3kb2024-11-07 15:36:552024-11-07 15:36:56

Judging History

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

  • [2024-11-07 15:36:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9836kb
  • [2024-11-07 15:36:55]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

#define N 1000005
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f

inline int R() {
    int x=0; bool f=0; char c=getchar();
    while (!isdigit(c)) f|=(c=='-'),c=getchar();
    while (isdigit(c)) x=x*10+c-'0',c=getchar();
    return f?-x:x;
}

template<typename T>
void W(T x,int op=0) {
    if (x<0) return putchar('-'),W(-x,op);
    if (x>9) W(x/10); putchar(x%10+'0');
    if (op) putchar(op==1?' ':'\n');
}

using namespace std;
int n,a[N],b[N],x[N],k,c[N]; LL sum[N];

int main() {
    // freopen("b.in","r",stdin);
    n=R();
    for (int i=1;i<=n;i++)
        c[++k]=a[i]=R(),c[++k]=b[i]=R(),x[i]=R();
    c[++k]=1; LL Sum=0;
    sort(c+1,c+k+1); k=unique(c+1,c+k+1)-c-1;
    for (int i=1;i<=n;i++) {
        a[i]=lower_bound(c+1,c+k+1,a[i])-c;
        b[i]=lower_bound(c+1,c+k+1,b[i])-c;
        sum[a[i]]+=x[i],sum[b[i]]+=x[i],Sum+=2*x[i];
    }
    for (int i=1;i<=k;i++) sum[i]+=sum[i-1];
    for (int i=1;i<=k;i++) sum[i]=2*sum[i]-Sum;
    LL ans=-INF;
    for (int i=1,j=k;i<=k;i++) {
        while (j>1 and sum[j]-4ll*c[i]*c[j]<sum[j-1]-4ll*c[i]*c[j-1]) --j;
        ans=max(ans,sum[i]+sum[j]-4ll*c[i]*c[j]);
    }
    W(ans,2);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9836kb

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'