QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#396789 | #7904. Rainbow Subarray | ucup-team3294 | WA | 239ms | 9100kb | C++14 | 2.0kb | 2024-04-23 10:30:49 | 2024-04-23 10:30:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+10;
multiset<int> se1,se2;
int sum1=0,sum2=0;
void balance()
{
if(se1.size()>se2.size())
{
auto t1=se1.rbegin();
sum2+=*t1;
se2.insert(*t1);
sum1-=*t1;
auto cnt=se1.find(*t1);
se1.erase(cnt);
}
else if(se2.size()-se1.size()==2)
{
auto t2=se2.begin();
sum1+=*t2;
se1.insert(*t2);
sum2-=*t2;
se2.erase(t2);
}
}
void solve()
{
int l=1;
se1.clear();
se2.clear();
sum1=0,sum2=0;
int n,k;
cin>>n>>k;
vector<int> a(n+1,0);
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]-=i;
}
int ans=1;
for(int i=1;i<=n;i++)
{
// cout<<"aa"<<endl;
if(se2.size())
{
auto t=se2.begin();
if(a[i]<*t)
{
se1.insert(a[i]);
sum1+=a[i];
balance();
}
else
{
se2.insert(a[i]);
sum2+=a[i];
balance();
}
}
else
{
se2.insert(a[i]);
sum2+=a[i];
balance();
}
int t=*se2.begin();
int res1=t*se1.size()-sum1;
int res2=sum2-t*se2.size();
//cout<<res1<<"aa"<<res2<<endl;
if(res1+res2<=k)
{
ans=max(ans,i-l+1);
}
else if(l<i)
{
if(a[l]>=t)
{
sum2-=a[l];
auto tt=se2.find(a[l]);
se2.erase(tt);
balance();
}
else
{
sum1-=a[l];
auto tt=se1.find(a[l]);
se1.erase(tt);
balance();
}
l++;
i--;
}
}
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3552kb
input:
5 7 5 7 2 5 5 4 11 7 6 0 100 3 4 5 99 100 5 6 1 1 1 1 1 5 50 100 200 300 400 500 1 100 3
output:
4 3 5 1 1
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 239ms
memory: 9100kb
input:
11102 2 167959139 336470888 134074578 5 642802746 273386884 79721198 396628655 3722503 471207868 6 202647942 268792718 46761498 443917727 16843338 125908043 191952768 2 717268783 150414369 193319712 6 519096230 356168102 262263554 174936674 407246545 274667941 279198849 9 527268921 421436316 3613460...
output:
1 4 1 2 6 5 7 2 4 1 4 1 1 2 2 2 7 7 7 7 1 6 5 2 4 3 1 5 7 7 3 4 3 9 3 8 6 6 1 1 5 1 1 2 4 5 4 6 4 1 3 6 1 6 3 5 6 6 1 7 5 3 1 6 3 5 3 2 2 6 1 3 10 1 4 1 1 4 5 1 5 5 5 5 8 5 3 6 3 5 5 8 5 3 5 2 1 5 2 2 3 4 8 1 3 1 2 2 8 3 1 6 8 1 8 4 5 6 6 7 2 8 3 2 7 4 5 5 2 6 2 4 1 5 4 5 2 2 4 1 2 1 2 3 8 3 6 3 3 2...
result:
wrong answer 3rd lines differ - expected: '3', found: '1'