Monday, September 16, 2024

# Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2), problem: (E) Aquarium decoration Solution In C/C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 200010
#define ll long long
#define INF 2000000000
ll Ans=1e18,Res;
int i,j,k,n,Sum,m,x,y,l[4],a[N],b[4][N],p[4],M,f[N];
inline int Min(int x,int y){return x<y?x:y;}
inline ll Min(ll x,ll y){return x<y?x:y;}
int main(){
scanf(“%d%d%d”,&n,&m,&k);
for(i=1;i<=n;i++)scanf(“%d”,&a[i]);
scanf(“%d”,&x);
while(x–)scanf(“%d”,&y),f[y]=1;
scanf(“%d”,&x);
while(x–){
scanf(“%d”,&y);
if(f[y])f[y]=3;else f[y]=2;
}
for(i=1;i<=n;i++)
if(f[i]==3)b[0][++l[0]]=a[i];else
if(f[i]==1)b[1][++l[1]]=a[i];else
if(f[i]==2)b[2][++l[2]]=a[i];else b[3][++l[3]]=a[i],f[i]=l[3];
sort(b[0]+1,b[0]+l[0]+1);sort(b[1]+1,b[1]+l[1]+1);
sort(b[2]+1,b[2]+l[2]+1);sort(b[3]+1,b[3]+l[3]+1);
for(i=0;i<4;i++)b[i][l[i]+1]=INF,p[i]=1;
for(i=0;i<=l[0]&&i<=m;i++){
if(k-i>l[1]||k-i>l[2])continue;
while(p[0]<=i){
Res+=b[0][p[0]++];
Sum++;
}
if(k-i+2==p[1]){
Res-=b[1][–p[1]];
Sum–;
}
while(k-i>=p[1]){
Res+=b[1][p[1]++];
Sum++;
}
if(k-i+2==p[2]){
Res-=b[2][–p[2]];
Sum–;
}
while(k-i>=p[2]){
Res+=b[2][p[2]++];
Sum++;
}
while(Sum<m){
M=INF;
for(j=0;j<4;j++)if(p[j]<=l[j])M=Min(M,b[j][p[j]]);
if(M==INF)break;
for(j=0;j<4;j++)
if(b[j][p[j]]==M){
Res+=b[j][p[j]++];
break;
}
Sum++;
}
if(Sum==m)Ans=Min(Ans,Res);
}
if(Ans==1e18)puts(“-1”);else printf(“%I64d\n”,Ans);
return 0;
}

## Celebrating Black History Month:...

As February unfolds, so does the annual celebration of...

## The Path to Self-Mastery:...

Embarking on a journey of self-mastery and breaking free...

## Wizards of Waverly Place...

In a spellbinding announcement, Disney has officially revealed that...

## Jim Irsay’s Reported ‘Suspected...

In a shocking turn of events last month, Jim...

Coachella Valley Music and Arts Festival, one of the...

## 2024 Taiwan Election: Pivotal...

As Taiwan gears up for its 2024 presidential election,...

### Celebrating Black History Month: Past, Future

As February unfolds, so does the annual celebration of Black History Month, a time to reflect on the profound contributions, resilience, and rich cultural...

### The Path to Self-Mastery: Lessons from Book ‘The Mountain Is You’

Embarking on a journey of self-mastery and breaking free from self-sabotage is a transformative process that requires dedication and conscious effort. Brianna Wiest's insightful...

### Wizards of Waverly Place Cast Reunites for Enchanting Revival

In a spellbinding announcement, Disney has officially revealed that the beloved fantasy series "Wizards of Waverly Place" is set for a magical comeback, featuring...

### Jim Irsay’s Reported ‘Suspected Overdose’: A Closer Look

In a shocking turn of events last month, Jim Irsay, the owner of the Indianapolis Colts, was reportedly found unresponsive at his home in...

### Coachella 2024: Iconic headliners, unforgettable musical experience!

Coachella Valley Music and Arts Festival, one of the most iconic and eagerly anticipated music festivals globally, has just dropped its highly anticipated lineup...

### 2024 Taiwan Election: Pivotal Moment in Political Landscape

As Taiwan gears up for its 2024 presidential election, the political landscape is buzzing with anticipation and fervor. With the island nation situated at...

### Michael Strahan’s Daughter’s Medulloblastoma Diagnosis

In a recent and heartbreaking revelation, Michael Strahan, former NFL star and television personality, shared the devastating news of his daughter Isabella's diagnosis with...

### Michigan vs. Washington: The 2024 National Championship Clash

In a highly anticipated matchup, the 2024 National Championship will witness a clash of football titans as the Michigan Wolverines square off against the...

### Jason Kelce: Unmasking the Unconventional NFL Icon

In the world of professional football, where conformity often takes center stage, one player stands out as a beacon of individuality, both on and...