codeforces493B
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"
Examples
5
1
2
-3
-4
3
second
3
-1
-2
3
first
2
4
-4
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.
sol:直接按照题意O(n)模拟就可以了,注意和会爆int
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N],b[N];
int main()
{
int i,opt=;
ll A=,B=,Last;
R(n);
for(i=;i<n;i++)
{
ll x=read();
if(x>)
{
a[++*a]=x; A+=1ll*x;
}
else
{
x=-x; b[++*b]=x; B+=1ll*x;
}
}
R(Last);
if(Last>)
{
a[++*a]=Last; A+=Last;
}
else
{
b[++*b]=-*Last; B+=-*Last;
}
if(A!=B)
{
(A>B)?puts("first"):puts("second");
}
else
{
for(i=;i<=max(*a,*b);i++) if(a[i]!=b[i])
{
(a[i]>b[i])?puts("first"):puts("second");
return ;
}
if(Last>) puts("first");
else puts("second");
}
return ;
}
/*
input
3
1000000000
1000000000
1000000000
output
first
*/
codeforces493B的更多相关文章
随机推荐
- jvm调优-从eclipse开始
一.概述 什么是jvm调优呢?jvm调优就是根据gc日志分析jvm内存分配.回收的情况来调整各区域内存比例或者gc回收的策略:更深一层就是根据dump出来的内存结构和线程栈来分析代码中不合理的地方给予 ...
- linux内存源码分析 - 内存池
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 内存池是用于预先申请一些内存用于备用,当系统内存不足无法从伙伴系统和slab中获取内存时,会从内存池中获取预留的 ...
- AWS re:Invent(2019.01.09)
时间:2019.01.09地点:北京国际饭店
- Spring MVC 5 + Thymeleaf 基于Java配置和注解配置
Spring MVC 5 + Thymeleaf 注解配置 Spring的配置方式一般为两种:XML配置和注解配置 Spring从3.0开始以后,推荐使用注解配置,这两种配置的优缺点说的人很多,我就不 ...
- Java正则表达式初探(一)
好多同学们总是听别人说起正则表达式这个东西,也有很多用接触到实际使用过.但是相信有很大一部分人是在用的时候采取网站上搜索,拿一个一知半解的别人写的例子过来,简单测试下功能可用,就OK了.正则表达式那晦 ...
- 分享一个公众号h5裂变吸粉源码工具
这次我是分享我本人制作的一个恶搞程序,说白了就是一个公众号裂变吸粉工具,市面上有很多引流方法,例如最常见的就是色流,哈哈,今天我跟大家分享的方法是有趣的,好玩的,恶搞的.这个程序上线一天已经收获了61 ...
- 使用JWT来实现对API的授权访问
目录 什么是JWT JWT的结构 Header Payload Signature 解码后的JWT JWT是怎样工作的 在JAVA里使用JWT 引入依赖 JWT Service 生成JWT 解码JWT ...
- 朱晔的互联网架构实践心得S1E9:架构评审一百问和设计文档五要素
朱晔的互联网架构实践心得S1E9:架构评审一百问和设计文档五要素 [下载文本PDF进行阅读] 本文我会来说说我认为架构评审中应该看的一些点,以及我写设计文档的一些心得.助你在架构评审中过五关斩六将,助 ...
- hibernate多对多的更新问题
错误原因 A different ]; nested exception ]] with root cause org.hibernate.NonUniqueObjectException: A di ...
- webapack
webpack 就是一个前端资源加载.打包工具. 核心思想:会根据(js css less文件)模块依赖关系进行静态分析,然后将这些模块按照指定的规则生成对应的静态资源,减少页面请求. wapack ...