B. Vasya and Wrestling
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output

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
input
3
-1
-2
3
output
first
input
2
4
-4
output
second
Note

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

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

模拟

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
ll i,j,t,n,m,l,r,k,z,y,x;
ll a[200005],b[200005];
ll suma,sumb;
int main()
{
scanf("%I64d",&n);
a[0]=b[0]=0;
suma=sumb=0;
for (i=1;i<=n;i++)
{
scanf("%I64d",&x);
if (x>0)
{
a[++a[0]]=x;
suma+=x;
}
if (x<0)
{
b[++b[0]]=-x;
sumb+=-x;
}
t=x;
}
if (suma>sumb) printf("first\n");
else if (suma<sumb) printf("second\n");
else
{
for (i=1;i<=max(a[0],b[0]);i++) if (a[i]!=b[i]) break;
if (a[i]>b[i]) printf("first\n");
else if (a[i]<b[i]) printf("second\n");
else
{
if (t>0) printf("first\n");
else printf("second\n");
}
}
return 0;
}

cf493B Vasya and Wrestling的更多相关文章

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

    B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...

  2. CodeForces 493B Vasya and Wrestling 【模拟】

    B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. codeforces 493B.Vasya and Wrestling 解题报告

    题目链接:http://codeforces.com/problemset/problem/493/B 题目意思:给出 n 个 techniques,每个 technique 的值为 ai. ai & ...

  4. Codeforces Round #281 (Div. 2)

    题目链接:http://codeforces.com/contest/493 A. Vasya and Football Vasya has started watching football gam ...

  5. codeforces493B

    Vasya and Wrestling CodeForces - 493B Vasya has become interested in wrestling. In wrestling wrestle ...

  6. Codeforces Round #281 (Div. 2) B 模拟

    B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. Milliard Vasya's Function-Ural1353动态规划

    Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make ...

  8. CF460 A. Vasya and Socks

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

随机推荐

  1. hadoop2.2.0 MapReduce的序列化

    package com.my.hadoop.mapreduce.dataformat; import java.io.DataInput;import java.io.DataOutput;impor ...

  2. iOS - UITableViewCell Custom Selection Style Color

    Customize UITextView selection color in UITableView Link : http://derekneely.com/2010/01/uitableview ...

  3. jQuery效果-滑动

    index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  4. 认识ptrace函数

    认识ptrace函数 这是man对于ptrace这个系统调用的解释 http://man7.org/linux/man-pages/man2/ptrace.2.html #include <sy ...

  5. 近段时间学习html和CSS的一些细碎总结

    1.边框圆角属性:border-radius,取值能够是 百分比 / 自己定义长度,不能够取负值.假设是圆,将高度和宽度设置相等,而且将border-radius设置为100% 2.IE6,IE7,I ...

  6. DevExpress GridView.CustomSummaryCalculate 实现自定义Group Summary

    --首发于博客园, 转载请保留链接  博客原文 DevExpress Documentation官方地址:GridView.CustomSummaryCalculate Event 1. 概要 界面上 ...

  7. IE下判断IE版本语法使用

    先摆一下判断IE版本语法 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![ ...

  8. jquery之多重判断

    var appPath = getAppPath(); $(function(){ $('#addTeskDlg').window('close'); teskGrid(); }); function ...

  9. 配置Samba服务

    1. samba服务用在什么地方?samba服务用于把Linux服务器上的文件或者打印接共享给windows或者Linux.2. 在samba服务的配置文件中,[global]配置部分的securit ...

  10. ADO.NET之使用DataGridView控件显示从服务器上获取的数据

    今天回顾下ADO.NET中关于使用DataGridiew控件显示数据的相关知识 理论整理: 使用 DataGridView 控件,可以显示和编辑来自多种不同类型的数据源的表格数据. SqlDataAd ...