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 <string.h>
#define M 250050
typedef unsigned long long LL; int a[M], b[M]; int main(){
int n;
while(~scanf("%d", &n)){
int temp, i, j;
int flag = -1, la, lb;
la = lb = 0;
LL sum1, sum2;
sum1 = sum2 = 0;
for(i = 0; i < n; i ++){
scanf("%d", &temp);
if(temp > 0){
sum1 +=temp;
flag = 1;
a[la++] = temp;
}
else {
temp = -temp;
sum2 += temp;
flag = 2;
b[lb++] = temp;
}
}
if(sum1 > sum2){
printf("first\n");
}
else if(sum1 < sum2){
printf("second\n");
}
else{
i = 0; j = 0;
int ok = 0;
while(i<la&&j<lb){
if(a[i] == b[j]){
++i; ++j;
}
else{
if(a[i] > b[j]) puts("first");
else puts("second");
return 0;
}
}
if(la >lb){
printf("first\n"); return 0;
}
if(la < lb){
printf("second\n");
return 0;
}
if(flag == 1) printf("first\n");
else printf("second\n");
}
}
return 0;
}

CodeForces 493B Vasya and Wrestling 【模拟】的更多相关文章

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

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

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

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

  3. cf493B Vasya and Wrestling

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

  4. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  5. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  6. Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟

    A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...

  7. Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)

    简单题,却犯了两个错误导致WA了多次. 第一是程序容错性不好,没有考虑到输入数据中可能给实际已经罚下场的人再来牌,这种情况在system测试数据里是有的... 二是chronologically这个词 ...

  8. codeforces C. Vasya And The Mushrooms (思维+模拟)

    题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...

  9. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

随机推荐

  1. 特殊字符导致json字符串转换成json对象出错

    在对数据库取出来的数据(特别是描述信息)里面含有特殊字符的话,使用JSON.parse将json字符串转换成json对象的时候会出错,主要是双引号,回车换行等影响明显,左尖括号和右尖括号也会导致显示问 ...

  2. 初始化ArrayList的两种方法[转]

    方式一:  ArrayList<String> list = new ArrayList<String>();  String str01 = String("str ...

  3. Java 三大主流 工作流 学习

    之前听同学说,他们在用工作流,好奇,搜索了一下,查看和搜集了一番,摘抄入下:(来源于:gzRiven) 三大主流工作流引擎:Shark,osworkflow,jbpm! Shark的靠山是Enhydr ...

  4. oracle11g-R2静默安装报错[INS-32013]解决方案

    问题描述: oracle静默安装很强大...,参数搞不对.安装就扯dan了....这个报错搞了一个下午.终于搞定了如释负重.... 如果当初选择仅仅安装oracle软件就没多事情.想一步完成(数据库软 ...

  5. 创业成本?亲身经历告诉你做一个app要多少钱

    导语:作为一名苦逼的移动互联网创业者,被外行的朋友们问及最多的问题是“做一个网站需要多少钱?”或者“做一个APP需要多少钱?” 作为一名苦逼的移动互联网创业者,被外行的朋友们问及最多的问题是“做一个网 ...

  6. Ubuntu下使用git提交代码至GitHub

    一.Ubuntu下安装Git Ubuntu12.04 LTS默认是已经安装Git的,可以使用 git --version 测试是否安装. 如果没有安装,使用命令: sudo apt-get insta ...

  7. ios中非ARC项目中引用ARC文件

    下图即可 选中工程->TARGETS->相应的target然后选中右侧的“Build Phases”,向下就找到“Compile Sources”了.如何在未使用arc的工程中引入一个使用 ...

  8. SSD 为什么顺序写比随机写性能更好?

    SSD以Page为单位做读写,以Block为单位做垃圾回收,Page一般有16KB大小,Block一般有几十MB大小,SSD写数据的逻辑是: 1)将该块数据所在的Page读出 2)修改该Page中该块 ...

  9. 快排法求第k大

    快排法求第k大,复杂度为O(n) import com.sun.media.sound.SoftTuning; import java.util.Arrays; import java.util.Ra ...

  10. 注意Hibernate4在开发当中的一些改变(转)

    注意Hibernate4在开发当中的一些改变 原文:http://hi.baidu.com/austincao/item/fc9907da3d854e44fa576861 Hibernate4的改动较 ...