代码:
#include <bits/stdc++.h>
#define int long long
using namespace std ;
struct stu{
int a ;
int b ;
bool chop = false ;
bool chos = false ;
bool cho = false ;
int ii ;
int aii ;
};
int n , p , s , p_num , s_num ;
stu a[3100] , b[3100] , cnt ;
bool cmp1 (stu x , stu y ){
if( x.a != y.a ){
return x.a > y.a ;
}else{
return x.b < y.b ;
}
}
bool cmp2 ( stu x , stu y ){
if( x.cho == false && y.cho == false ){
return x.b > y.b ;
}
if( x.cho == false && y.cho == true ){
if( y.b - y.a == x.b || y.b - y.a == -x.b ){
return y.cho < x.cho ;
}else{
return x.b > (y.b - y.a) ;
}
}
if( x.cho == true && y.cho == false ){
if( x.b - x.a == y.b || x.b - x.a == -y.b ){
return x.cho < y.cho ;
}else{
return (x.b - x.a )<y.b ;
}
}
if( x.cho == true && y.cho == true ){
return ( x.b - x.a ) > ( y.b - y.a );
}
}
signed main(){
int cnt = 1 ;
cin >> n >> p >> s ;
for( int i = 1 ; i <= n ; i ++ ){
cin >> a[i].a ;
a[i].ii = i ;
}
int pc = p ;
for( int i = 1 ; i <= n ; i ++ ){
cin >> a[i].b ;
}
sort( a+1 , a+n+1 , cmp1 );
for( int i = 1 ; i <= p ; i ++ ){
p_num += a[i].a ;
a[i].cho = true ;
a[i].chop = true ;
a[i].chos = false ;
}
sort( a+1 , a+n+1 , cmp2 );
for( int i = 1 ; i <= s ; i ++ ){
if( a[i].cho == false ){
s_num += a[i].b ;
a[i].cho = true ;
a[i].chop = false ;
a[i].chos = true ;
}else{
if( a[i].cho == true){
s_num += a[i].b ;
p_num -= a[i].a ;
pc -- ;
a[i].chos = true ;
a[i].chop = false ;
}
}
}
for( int i = 1 ; i <= n ; i ++ ){
if(a[i].cho == false ){
b[cnt] = a[i] ;
b[cnt++].aii = i ;
}
}
sort( b+1 , b+cnt , cmp1 );
cnt -= 1 ;
for(int i = 1 ; i <= p-pc ; i ++ ){
p_num += b[i].a ;
a[b[i].aii].cho = true ;
a[b[i].aii].chop = true ;
a[b[i].aii].chos = false ;
}
cout << p_num+s_num << endl;
for( int i = 1 ; i <= n ; i ++ ){
if( a[i].chop == true ){
cout << a[i].ii << " ";
}
}
cout << endl ;
for( int i = 1 ; i <= n ; i ++ ){
if( a[i].chos == true ){
cout << a[i].ii << " ";
}
}
cout << endl ;
return 0 ;
}
input:
5 2 1
9 10 1 7 10
6 10 8 6 3
answer:
29
1 5
2
output:
28
2 5
3