結果
| 問題 |
No.2248 max(C)-min(C)
|
| コンテスト | |
| ユーザー |
hiro71687k
|
| 提出日時 | 2023-03-18 15:22:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,421 bytes |
| コンパイル時間 | 3,751 ms |
| コンパイル使用メモリ | 255,624 KB |
| 最終ジャッジ日時 | 2025-02-11 15:06:37 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 WA * 6 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll inf=1001000000000;
ll mod=1000000007;
int main(){
ll n;
cin >> n;
vector<ll>a(n),b(n);
for (ll i = 0; i < n; i++)
{
cin >> a[i];
}
for (ll i = 0; i < n; i++)
{
cin >> b[i];
}
if (n==1)
{
cout <<0 << endl;
return 0;
}
ll left=-1,right=inf;
ll ans=inf;
while (right-left>1)
{
ll mid=(right+left)/2;
bool ok=true;
vector<ll>x;
for (ll i = 0; i < n; i++)
{
vector<ll>c;
if (a[i]>=mid)
{
c.push_back(a[i]);
}
if (b[i]>=mid)
{
c.push_back(b[i]);
}
if ((a[i]+b[i])/2>=mid)
{
c.push_back((a[i]+b[i])/2);
}
if (c.empty())
{
ok=false;
break;
}
sort(c.begin(),c.end());
x.push_back(c[0]);
}
if (!ok)
{
right=mid;
continue;
}else{
left=mid;
}
sort(x.begin(),x.end());
if (x[x.size()-1]-x[0]<ans)
{
ans=x[x.size()-1]-x[0];
}
}
cout << ans << endl;
}
hiro71687k