Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

B. Vasya and Wrestling
 

Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.

When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.

If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

Input

The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).

The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.

The techniques are given in chronological order.

Output

If the first wrestler wins, print string "first", otherwise print "second"

Sample test(s)
input
5
1
2
-3
-4
3
output
second
 
Note

Sequence x  =  x1x2... x|x| is lexicographically larger than sequence y  =  y1y2... y|y|, if either |x|  >  |y| andx1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r (r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr andxr  +  1  >  yr  +  1.

We use notation |a| to denote length of sequence a.

 题意:两个人进行比赛, 给你n轮的分数,正数为first的,负数为second的分数,问你最后谁赢,分数多的赢,如果分数相同按照字典序大小比较,如果字典序也相同,按照谁最后一轮谁得分谁赢

题解:没什么好说的,看清题意就是了

///meek
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';ch=getchar();
    }return x*f;
}
//****************************************
const int N=200005;
#define mod 10000007
#define inf 10000007
#define maxn 10000
int f[200005],s[N],k=0,kk=0;
int main() {
   ll ans=0,a;
    ll n=read();
    for(int i=1;i<=n;i++) {
        scanf("%I64d",&a);
        ans+=a;
        if(a>0) {
            f[++k]=a;
        }
        else s[++kk]=-a;
    }
    if(ans>0) {
        cout<<"first"<<endl;
    }
    else if(ans<0)cout<<"second"<<endl;
    else {
       for(int i=1;i<=min(kk,k);i++) {
        if(f[i]>s[i]) { cout<<"first"<<endl;return 0;}
        else if(f[i]<s[i]) {cout<<"second"<<endl;return 0;}
       }
      if(kk>k) {
          cout<<"second"<<endl;return 0;
       }
       else if(kk<k) {cout<<"first"<<endl;return 0;}
       if(a>0) {
          cout<<"first"<<endl;
    }
       else cout<<"second"<<endl;
    }
    return 0;
}
代码
原文地址:https://www.cnblogs.com/zxhl/p/4979295.html