Thursday, May 7, 2015

493B - Vasya and Wrestling (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 10000
typedef long long ll;
vector<int> a, b;

int main()
{
    ll n, m, sum1, sum2, i, sz, j;
    int last, cnt , ans ;
    while(cin >> n)
    {
        ans =0;
        cnt=0;
        sum1 = sum2 = 0;
        a.clear();
        b.clear();
        loop(j,n)
        {
            cin >> m;
            if(j==(n-1)) last = m;
            if(m>0)
            {
                a.push_back(m);
                sum1 +=m;
            }
            else
            {
                m *=(-1);
                b.push_back(m);
                sum2 += m;
            }
        }
        sz=0;
        //cout << sum1 << " " << sum2 << endl;
        if(sum1>sum2) ans = 1;
        else if(sum2>sum1) ans = 2;
        else
        {
            if(a.size()> b.size()) sz = b.size();
            else                   sz = a.size();
            loop(i, sz)
            {
                if(a[i]>b[i])
                {
                    ans = 1;;
                    cnt++;
                    break;
                }
                else if(a[i]<b[i])
                {
                    ans = 2;
                    cnt++;
                    break;
                }
            }
            if(cnt==0)
            {
                if(last>0) ans = 1;
                else       ans = 2;
            }
        }
        if(ans==1) cout << "first" << endl;
        else if(ans==2) cout << "second" << endl;
    }
    return 0;
}

No comments:

Post a Comment

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...