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的更多相关文章
随机推荐
- NCC Meetup 2018 Shanghai 活动小结(含PPT与视频)
NCC Meetup 2018 上海的活动于2018年6月30日在微软上海港汇办公室进行.原本计划30人规模的小型活动,结果收到了逾60人的报名,其中大部均来到现场参加了活动. 本次活动得到了微软公司 ...
- Linux Namespace : 简介
在初步的了解 docker 后,笔者期望通过理解 docker 背后的技术原理来深入的学习和使用 docker,接下来的几篇文章简单的介绍下 linux namespace 的概念以及基本用法. na ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统-WebApi的用法与调试
1:ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-WebApi与Unity注入 使用Unity是为了使用我们后台的BLL和DAL层 2:ASP.NET MVC5+EF6+Easy ...
- eclipse maven 常见问题解决方案
一.eclipse集成与设置 传送门:http://www.cnblogs.com/tweet/p/7602044.html 二.创建maven webapp工程,报错 报错信息:Could not ...
- flask登录插件 flask-login
Flask-Login为Flask提供了用户会话管理,它处理了日常的登入登出且长时间记住用户的会话 使用: 1.配置,初始化 LoginManager 创建实例 loginManger = Login ...
- 八、xadmin自定义菜单栏顺序
xadmin默认是读取注册的app和所有注册到xadmin的mode来生成对应的菜单. nav_menu[app_key] = { 'title': app_title, 'menus': [mode ...
- koa服务器搭建基础
之前我一直使用rails搭建网站.rails与koa的基本理念很相似,都是基于中间件提供一层层的服务.所不同的是,rails有很多内置的中间件,这使得开发者只需要关注MVC模块以及页面路由.而Koa这 ...
- Mergeable Stack(链表实现栈)
C - Mergeable Stack ZOJ - 4016 一开始用stl中内置的栈来写,其中第三个操作,我先复制到一个数组,再将其倒给另一个栈 这个方法有两个错误的地方: 1.栈在内存很大需要扩容 ...
- mysql_查的小理解
show create table employee; 对这个语句的小理解: 顿悟呀,之前一直不太理解这条语句,现在忽然觉得明朗起来.他就是展示创建这个表格时的SQL语句.执行上述代码之后结果如下: ...
- MYSQL行号
mysql 实现行号的方法——如何获取当前记录所在行号 - senly - 博客园http://www.cnblogs.com/xinlei/archive/2011/12/16/2290349.ht ...