QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#810749 | #9331. Maximize the Minimum | SFlyer | WA | 67ms | 5708kb | C++14 | 1.6kb | 2024-12-12 10:29:23 | 2024-12-12 10:29:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 4e5+5;
ll n,m,s,sum;
struct node {
ll x,y,op;
} a[N];
bool cmp(node u,node v){
return u.x<v.x;
}
ll dp[N][2],mx[2][2],fmx[2][2];
bool chk(ll mid){
memset(mx,-0x3f,sizeof mx);
memset(fmx,-0x3f,sizeof fmx);
mx[0][0]=mx[1][0]=0;
for (int i=1,j=1; i<=n; i++){
int f=a[i].op;
while (j<=n && a[j].x<=a[i].x-mid){
for (int c=0; c<2; c++){
fmx[a[j].op][c]=max(fmx[a[j].op][c],dp[j][c]);
}
j++;
}
memset(dp[i],-0x3f,sizeof dp[i]);
for (int c=0; c<2; c++){
dp[i][c]=max(dp[i][c],mx[f][c]+a[i].y);
dp[i][1]=max(dp[i][1],fmx[f^1][c]+a[i].y);
}
mx[f][0]=max(mx[f][0],dp[i][0]);
mx[f][1]=max(mx[f][1],dp[i][1]);
}
return max(mx[0][1],mx[1][1])>=sum-s;
}
void solve(){
cin>>n>>m>>s;
sum=0;
for (int i=1; i<=n+m; i++) cin>>a[i].x;
for (int i=1; i<=n+m; i++){
cin>>a[i].y;
a[i].op=(i>n);
sum+=a[i].y;
}
n+=m;
sort(a+1,a+1+n,cmp);
ll l=-1,r=2e9+1;
while (l+1<r){
ll mid=l+r>>1;
if (chk(mid)) l=mid;
else r=mid;
}
cout<<l<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
solve();
}
return 0;
}
// TRY! TRY! TRY!
/*
Think twice before coding. Have you overkilled?
Think twice before submitting.
Check on the samples and constraints carefully.
*/
/*
Be brave to guess.
Is your former/first approach correct?
Follow your intuition.
Use a notebook to note down your ideas and check whether they are correct.
*/
/*
A simple brute force may work? There is some limit on the answer?
Try to find patterns.
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5708kb
input:
2 1 4 10 15 1 6 9 13 8 3 1 2 4 5 4 4 -1 5 3 2 -4 -7 8 6 2 2 3 1 1 2 3 1 1 1
output:
14 3
result:
ok 2 number(s): "14 3"
Test #2:
score: -100
Wrong Answer
time: 67ms
memory: 5708kb
input:
40000 5 3 4 1 -5 -2 -5 4 -3 -4 -4 4 8 2 4 7 5 3 7 5 3 6 -4 -7 -4 -1 -7 -4 -4 -2 6 8 3 4 5 5 3 5 5 3 6 -1 2 3 -4 -1 -1 -2 -3 8 3 4 3 2 2 5 2 5 3 4 -5 -2 3 -1 2 -3 0 -2 6 5 1 1 6 7 8 7 5 3 4 0 0 1 -4 -2 -4 -4 -3 7 7 5 8 3 8 2 4 5 3 4 0 -4 -1 1 -6 -2 -5 -4 7 4 5 7 3 5 5 2 5 3 6 -4 -3 0 2 -4 -5 -4 -4 6 ...
output:
-1 0 1 -1 0 -1 0 -1 -1 -1 -1 -1 1 2 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 3 -1 1 -1 0 -1 1 1 2 -1 0 1 1 -1 -1 -1 1 -1 2 2 4 -1 -1 1 0 0 -1 0 -1 -1 2 0 0 0 2 -1 1 0 0 1 2 1 -1 3 -1 1 1 4 2 -1 0 -1 -1 0 2 0 3 1 0 1 1 0 -1 0 -1 -1 2 0 1 0 -1 0 0 -1 1 1 1 -1 0 2 2 -1 1 -1 1 -1 -1 1 -1 0 0 2 0 2 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st numbers differ - expected: '1', found: '-1'