|
|
вернуться в форумWA please help me! I got WA 5 #include <iostream> using namespace std; int main() { int d,m,sd=0,sm=0,i,k=0,l; bool f = true; cin>>d>>m; int *mass1 = new int[d]; int *mass2 = new int[m]; for(i=0;i<d;i++) {cin>>mass1[i]; sd+=mass1[i];} for(i=0;i<m;i++) {cin>>mass2[i]; sm+=mass2[i];} while(f) { f=false; for(i=0;i<d;i++) {if(mass1[i]<mass1[i+1]) swap(mass1[i],mass1[i+1]), f = false;} } f = true; while(f) { f=false; for(i=0;i<m;i++) {if(mass2[i]<mass2[i+1]) swap(mass2[i],mass2[i+1]), f = false;} } l=min(d,m); int *g = new int[l]; for(i=0;i<=l;i++) { if(i!=0) {sm=sm-mass2[i-1],sd=sd-mass1[i-1];} g[i]=i*sm+sd; } for(i=0,k=g[0];i<=l;i++) { if(g[i]<k) k=g[i]; } cout<<k<<endl; } Re: WA if there is sorting, then while(f) { f=false; for(i=0;i<d;i++) {if(mass1[i]<mass1[i+1]) swap(mass1[i],mass1[i+1]), f = true/*!!!*/;} } use sort( mass1, mass1+d ); it's simpler:) Re: WA you use elements in position number d |
|
|