ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1788. On the Benefits of Umbrellas

WA
Posted by Nikolay 19 Oct 2010 17:06

#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
Posted by IgorKoval(from Pskov) 18 Sep 2011 19:33
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
Posted by {SESC USU} Zaynullin 8 Oct 2011 23:37
you use elements in position number d