QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#178082 | #6693. Fast and Fat | value0# | WA | 0ms | 4088kb | C++20 | 1.4kb | 2023-09-13 17:51:20 | 2023-09-13 17:51:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> pii;
#define fi first
#define se second
int n,m,k;
void solve()
{
scanf("%d",&n);
vector<pair<ll,int>> v(n + 1),w(n + 1),a(n + 1);
for(int i = 1;i<=n;i++)
{
scanf("%lld %lld",&v[i].fi,&w[i].fi);
v[i].se = w[i].se = i;
a[i] = {v[i].fi + w[i].fi,i};
}
sort(v.begin(),v.end());
sort(a.begin(),a.end());
int l = 0;
int r = 1e9 + 1;
auto check = [&](int x)
{
vector<int> t,ans;
vector<bool> st(n + 1);
for(int i = 1;i<=n;i++)
{
if(v[i].fi < x)
{
st[v[i].se] = true;
t.push_back(w[v[i].se].fi);
}
}
for(int i = n;i>=1;i--)
{
if(!st[a[i].se])
{
ans.push_back(a[i].fi - x);
}
}
reverse(ans.begin(),ans.end());
if(ans.size() < t.size())
{
return false;
}
int idx = ans.size()-1;
for(int i = t.size()-1;i>=0 && idx >= 0;i--)
{
while(idx >= 0 && ans[idx] < t[i])
{
idx --;
}
if(idx >= 0)
{
idx --;
t[i] = 0;
}
}
if(t.empty() || t[0] == 0)
{
return true;
}
return false;
};
while(l + 1 < r)
{
int mid = l + r >> 1;
// cout<<mid<<endl;
if(check(mid))
{
l = mid;
}
else
{
r = mid;
}
}
printf("%d\n",l);
}
int main()
{
int t = 1;
scanf("%d",&t);
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4088kb
input:
2 5 10 5 1 102 10 100 7 4 9 50 2 1 100 10 1
output:
7 1
result:
wrong answer 1st numbers differ - expected: '8', found: '7'