Cod sursa(job #1260047)

Utilizator ZeBuGgErCasapu Andreas ZeBuGgEr Data 10 noiembrie 2014 20:45:45
Problema Transport Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.27 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("transport.in");
    ofstream fout("transport.out");
    
    int n,k,last=-1,c=-1,temp=0,temp2,temp3=0;
    fin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
            fin>>a[i];
            temp+=a[i];
    }
    temp/=k;
    fout<<"* "<<temp<<'\n'<<c<<'\n';
    while(1)
    {
            temp2=temp;
            temp3=1;
            for(int i=0;i<n;i++)
            {
                    if(temp2-a[i]>=0)
                    {
                                     temp2-=a[i];
                    }
                    else
                    {
                        if(temp2==temp)
                        {
                                       last=c;
                                       c=0;
                                       temp++;
                                       break;
                        }
                        else
                        {
                            temp2=temp;
                            temp3++;
                            if(temp2-a[i]>=0)
                            {
                                             temp2-=a[i];
                            }
                            else
                            {
                                last=c;
                                c=0;
                                temp++;
                                break;
                            }
                        }
                    }
                    if(i==n-1)
                    {
                              last=c;
                              c=1;
                    }
            }
            fout<<"* "<<temp<<'\n'<<c<<'\n';
            if(c==1&&temp3<=k)
            {
                    temp--;
            }
            else if(c==0)
            {
                 temp++;
            }
            else if(temp3>k)
            {
                 temp++;
            }
            if(c==0&&last==1&&temp3<=k)
            {
                            temp--;
                            break;
            }
            else if(c==1&&last==0&&temp3<=k)
            {
                 temp++;
                 break;
            }
    }
    fout<<temp;
}