Cod sursa(job #1074208)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 7 ianuarie 2014 12:58:38
Problema Balanta Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.42 kb
#include <iostream>
#include <fstream>
using namespace std;
int max(int a[], int b)
{
    int m = 0;
    for(int i=0; i< b; i++)
    {
            if(a[i] > m) m = a[i];
    }
    return m;
}
int check(int a)
{
    if(a< 0)
    {
          return 0-a;
    }
    if(a> 2)
    {
          return a-2;
    }
    return 0;
}
int main()
{
    ifstream fin("balanta.in");
    ofstream fout("balanta.out");
    int n, m, temp1, temp2, p = 0;
    fin>>n;
    int arr[n], check_arr[n];
    for(int i=0; i< n; i++)
    {
            arr[i] = 1;
    }
    int temp[n];
    for(fin>>m; m>0; m--)
    {
            fin>>temp1;
            for(int j=0; j< 2*temp1; j++)
            {
                    fin>>temp[j];
            }
            fin>>temp2;
            if(temp2 != 0)
            {
                     if(temp2 == 1)
                     {
                              for(int j=0; j< temp1; j++)
                              {
                                      arr[temp[j] - 1]++;
                              }
                              for(int j=temp1; j< 2*temp1; j++)
                              {
                                      arr[temp[j] - 1]--;
                              }
                     }
                     else if(temp2 == 2)
                     {
                          for(int j=temp1; j< 2*temp1; j++)
                          {
                                  arr[temp[j] - 1]++;
                          }
                          for(int j=0; j< temp1; j++)
                          {
                                  arr[temp[j] - 1]--;
                          }
                     }
            }
            if(temp2 == 0)
            {
                     p = max(temp, 2*temp1);
                     for(int i =0; i< 2*temp1; i++)
                     {
                             arr[temp[i] - 1] = p;
                     }
            }
    }
    for(int i=0; i< n; i++)
    {
            check_arr[i] = check(arr[i]);
    }
    temp2 = max(check_arr, n);
    int count = 0;
    for(int i=0; i< n; i++)
    {
            if(check_arr[i] == temp2) count++;
    }
    p = 0;
    for(int i=0; i< n; i++)
    {
            if(arr[i] == max(arr, n)) p = i+1;
    }
    if(count > 1) p = 0;
    fout<<p<<endl;
    /*for(int i =0; i< n; i++)
    {
            cout<<arr[i]<<" ";
    }*/
    return 0;
}