Cod sursă (job #316998)

Utilizator avatar sabinanton Anton Sabin-Viorel sabinanton IP ascuns
Problemă Domino Compilator cpp | 0,93 kb
Rundă Arhiva de probleme Status evaluat
Dată 16 oct. 2017 15:57:22 Scor 8
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("domino.in");
ofstream fout("domino.out");
int n,v[10001],k,x[10001],a,b;
bool t[10001];
int main()
{
int i,j,vf=0,k1,k2,s,vf1,d;
   fin>>n>>k1>>k2;
   x[vf]=0;
   v[vf]=0;
   for(i=1;i<=n;i++)
   {
        fin>>s>>d;
        while(max(s,d)>max(v[vf],x[vf])&&vf>0||k2>0)
        {
            if(t[vf]==true)
            {
                t[vf]=false;
                k1++;
            }
            vf--;
            k2--;
        }
        //cout<<vf<<" "<<k1<<endl;
        vf++;
        if(k1>0&&s<d)
        {
            k1--;
            v[vf]=d;
            x[vf]=s;
            t[vf]=true;
        }

        else{
         v[vf]=s;
         x[vf]=d;
        }
        if(t[vf-1]==true&&a==s&&b==d)
        {
            t[vf]=true;
            t[vf-1]=false;
        }
        a=v[vf];
        b=x[vf];
   }
   for(i=1;i<=vf;i++)
  fout<<v[i]<<x[i];

    return 0;
}