Cod sursă (job #316986)

Utilizator avatar sabinanton Anton Sabin-Viorel sabinanton IP ascuns
Problemă Domino Compilator cpp | 0,76 kb
Rundă Arhiva de probleme Status evaluat
Dată 16 oct. 2017 15:10:59 Scor 44
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("domino.in");
ofstream fout("domino.out");
int n,v[1000001],k,x[1000001];
bool t[100001];
int main()
{
int i,j,vf=0,k1,k2,s,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--;
        }
        vf++;
        if(k1>0&&s<d)
        {
            k1--;
            v[vf]=d;
            x[vf]=s;
            t[vf]=true;
        }
        else{
         v[vf]=s;
         x[vf]=d;
        }

   }
   for(i=1;i<=vf;i++)
   {
   fout<<v[i]<<x[i];
   }
    return 0;
}