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的更多相关文章
随机推荐
- face detection[HR]
该模型hybrid-resolution model (HR),来自<finding tiny faces>,时间线为2016年12月 0 引言 虽然大家在目标识别上有了较好的进步,可是检 ...
- 在WinForm应用程序中快速实现多语言的处理(2)--开发框架模块的整合
我在上篇随笔<在WinForm应用程序中快速实现多语言的处理>里面介绍了Winform开发中多语言的处理解决方案,整个多语言解决方案是以实际需求为驱动,以减少代码改动,高效处理为目的,通过 ...
- 提取jedis源码的一致性hash代码作为通用工具类
一致性Hash热点 一致性Hash算法是来解决热点问题,如果虚拟节点设置过小热点问题仍旧存在. 关于一致性Hash算法的原理我就不说了,网上有很多人提供自己编写的一致性Hash算法的代码示例,我在跑网 ...
- Centos 7 修改系统时区
timedatectl status Local time: 四 2014-12-25 10:52:10 CST Universal time: 四 2014-12-25 02:52:10 UTC R ...
- Leetcode 2. Add Two Numbers(medium)
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
- c++入门之内置数组和array比较
array是C++11中新提出来的容器类型,与内置数组相比,array是一种更容易使用,更加安全的数组类型,可以用来替代内置数组.作为数组的升级版,继承了数组最基本的特性,也融入了很多容器操作,下面介 ...
- c++入门之输出文件流ofstream
# include "iostream" # include"fstream" int main() { using namespace std; ]; int ...
- PS电商产品banner设计
- Django之ORM操作(聚合 分组、F Q)
Django之ORM操作(聚合 分组.F Q) 聚合 aggregate()是QuerySet的一个终止子句,也就是说,他返回一个包含一些键值对的字典,在它的后面不可以再进行点(.)操作. 键的名 ...
- 3proxy使用方法
转自:DRL@fireinice写的教程 ******************************************************************************* ...