Cod sursa(job #1053243)
Utilizator | Data | 12 decembrie 2013 16:16:22 | |
---|---|---|---|
Problema | Transport | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.32 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream fin("transport.in");
ofstream fout("transport.out");
int n,k;
long int temp=0,sum,temp2=0,temp3=1;
bool check=1;
fin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
{
fin>>a[i];
temp+=a[i];
}
sum=temp;
temp/=k;
while(temp*k<sum)
{
temp++;
}
while(check==1)
{
check=0;
for(int i=0;i<n;i++)
{
if(a[i]>temp)
{
check=1;
temp++;
break;
}
}
}
while(1)
{
temp2=0;
temp3=1;
for(int i=0;i<n;i++)
{
if(temp2+a[i]<=temp)
{
temp2+=a[i];
}
else{
temp2=a[i];
temp3++;
}
}
if(temp3>k)
{
temp++;
}
else
{
break;
}
}
fout<<temp;
}