QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#34042 | #1880. Nikanor Loves Games | moyujiang | WA | 1ms | 7816kb | C++ | 1.4kb | 2022-06-05 15:31:48 | 2022-06-05 15:31:51 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
#define int long long
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
}
const int N=2e6+10;
#define fi first
#define se second
int n,m,sum,c;
map<int,int> mp;
int val[N],id[N];
struct node{
int x,y;
int val(int a){return x*a+y;}
}q[N];int L,R;
//bool check(node A,node B,node C){
// int x1=B.x-A.x,y1=B.y-A.y,x2=C.x-B.x,y2=C.y-B.y;
// return x1*y2-x2*y1>0;
//}
bool check(node A,node B,node C){//(k,b)
return (B.y-A.y)*(C.x-B.x)>(C.y-B.y)*(B.x-A.x);
}
signed main(){
n=read();
For(i,1,n){
int u=read(),v=read(),x=read();
mp[u]+=x,mp[v]+=x,sum-=2*x;
}for(auto x:mp)c++,id[c]=x.fi*2,sum+=2*x.se,val[c]=sum;
int ans=-1e18;
// For(i,1,c)For(j,i,c)ans=max(ans,val[i]+val[j]-id[i]*id[j]);
L=1,R=0;For(i,1,c){
node now=(node){id[i],val[i]};
while(L<R&&!check(q[R-1],q[R],now))R--;
q[++R]=now;
}For(i,1,c){
ans=max(ans,2*val[i]-id[i]*id[i]);
while(L<R&&q[R].val(-id[i])>=q[R-1].val(-id[i]))R--;
ans=max(ans,val[i]+q[R].val(-id[i]));
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7816kb
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'