hdu 1789 Doing Homework again
又是一次初始化惹的货!!!
超级水的贪心。。。害的我以为思路错误~~ ~
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;
struct Sub{
int dl, rs;
}sub[1005];
int flag[1005];
bool cmp(Sub a, Sub b){
if(a.dl!=b.dl) return a.dl<b.dl;
return a.rs>b.rs;
}
int main(){
int t, n, i, j, k, l, m, ans;
scanf("%d",&t);
while(t--){
memset(flag,0,sizeof(flag));
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&sub[i].dl);
}
for(i=0;i<n;i++){
scanf("%d",&sub[i].rs);
}
sort(sub,sub+n,cmp);
flag[0] = 1;
ans = 0;
j=1;
m=99999999;l=-1;
for(i=1;i<n;i++){
if(sub[i].dl<=j){
for(k=i-1;k>=0;k--){
l=-1; //万恶的这一句!!! 你害我查错,查了多久!!!
if(flag[k]&&sub[i].rs>sub[k].rs){
if(m>sub[k].rs){
m=sub[k].rs;
l = k;
}
cout<<"i:"<<i<<"l: "<<l<<endl;
}
}
if(l!=-1){
ans += sub[l].rs;
cout<<"ans: "<<ans<<endl;
flag[l]=0;
flag[i]=1;
}
else{
ans+=sub[i].rs;
cout<<"ans: "<<ans<<endl;
// j++;
}
}
else{
j++;
}
}
printf("%d\n",ans);
}
return 0;
}
/*9
4 3 7 3 4 1 1 6 7
10 6 8 47 16 7 6 3 4*/