QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646028 | #5076. Prof. Pang and Ants | Kevin5307 | WA | 0ms | 3764kb | C++23 | 2.4kb | 2024-10-16 20:57:13 | 2024-10-16 20:57:14 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
ll a[100100];
struct block
{
ll A,B,M;
block(){}
block(ll _A,ll _B,ll _M):A(_A),B(_B),M(_M){};
inline ll length(){return (B-A+1)*M;}
inline ll lget(ll x){return (x-1)/M+A;};
inline ll rget(ll x){return lget(length()-x+1);}
inline ll lgetd(ll x){return (x-1)/M*M+M-(x-1);}
inline ll rgetd(ll x){return lgetd(x);}
inline ll lgetd2(ll x){return (x-1)-(x-1)/M*M+1;}
inline ll rgetd2(ll x){return lgetd2(x);}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
ll m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]++;
}
sort(a+1,a+n+1);
vector<block> vec;
for(int i=1;i<n;i++)
if((a[i+1]-a[i])*i<=m)
{
vec.pb(a[i],a[i+1]-1,i);
m-=(a[i+1]-a[i])*i;
}
else
{
if(m/i)
vec.pb(a[i],a[i]+m/i-1,i);
if(m%i)
vec.pb(a[i]+m/i,a[i]+m/i,m%i);
m=0;
}
if(m/n)
vec.pb(a[n],a[n]+m/n-1,n);
if(m%n)
vec.pb(a[n]+m/n,a[n]+m/n,m%n);
ll L=0,R=0;
int lp=0,rp=sz(vec)-1;
ll ans=0;
while(lp<sz(vec))
{
if(L==vec[lp].length())
{
L=0;
lp++;
continue;
}
if(R==vec[rp].length())
{
R=0;
rp--;
continue;
}
ll len=min(vec[lp].length()-L,vec[rp].length()-R);
// ...
ans=max(ans,vec[lp].lget(L+1)+vec[rp].rget(R+1));
ans=max(ans,vec[lp].lget(L+len)+vec[rp].rget(R+len));
if(vec[lp].M>=vec[rp].M)
if(vec[lp].lgetd(L+1)<vec[rp].rgetd(R+1)&&vec[lp].lgetd(L+1)<=len-1)
ans=max(ans,vec[lp].lget(L+1)+vec[rp].rget(R+1)+1);
if(vec[lp].M<=vec[rp].M)
if(vec[lp].lgetd2(L+len)>vec[rp].rgetd2(R+len)&&vec[rp].rgetd2(R+len)<=len-1)
ans=max(ans,vec[lp].lget(L+len)+vec[rp].rget(R+len)+1);
L+=len;
R+=len;
}
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
3 2 4 1 2 3 10 1 2 3 5 1 1 2 3 4 5
output:
6 9 4
result:
ok 3 number(s): "6 9 4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3764kb
input:
1 1 100000000000000 1000000000
output:
100002000000001
result:
wrong answer 1st numbers differ - expected: '200000000000000', found: '100002000000001'