Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题
2014-12-04 16:53
316 查看
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
Output
Input
Output
Input
Output
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.
两个cha点:
LL和最后一发谁打谁赢
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.
两个cha点:
LL和最后一发谁打谁赢
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) ll kiss[1000000]; ll kill[1000000]; int main() { int n; cin>>n; ll ans1=0; ll ans2=0; int path1=0; int path2=0; int flag3=0; int num=0; for(int i=0;i<n;i++) { cin>>num; if(num<0) { kill[path2++]=-num; ans2-=num; } else { kiss[path1++]=num; ans1+=num; } if(i==n-1) { if(num<0) flag3=2; else flag3=1; } } //cout<<ans1<<" "<<ans2<<endl; int flag=0; if(ans1>ans2) { flag=1; } else if(ans2>ans1) { flag=2; } else { int len=min(path1-1,path2-1); for(int i=0;i<len+1;i++) { //cout<<kiss[i]<<" "<<kill[i]<<endl; if(kiss[i]>kill[i]) { flag=1; break; } if(kill[i]>kiss[i]) { flag=2; break; } } if(flag==0) { if(path1>path2) flag=1; else if(path2>path1) flag=2; else flag=flag3; } } if(flag==1) cout<<"first"<<endl; else cout<<"second"<<endl; return 0; }
相关文章推荐
- Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题
- codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 暴力水题
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- 【Codeforces Round 262 (Div 2)A】【水题】Vasya and Socks 妈妈买袜子 最多穿几天
- Codeforces #262 (Div. 2) A. Vasya and Socks(水题)
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力水题
- Codeforces Round #378 (Div. 2) A. Grasshopper And the String(水题求跳跃距离)
- Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) Codeforces932 A. Palindromic Supersequence(水题) B.Recursive Queries(前缀和) C.Permutation Cycle(数学)
- Codeforces Round #281 (Div. 2) A - Vasya and Football
- 【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b
- Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game
- Codeforces Round #354 (Div. 2) C. Vasya and String 二分
- Codeforces Round #404 (Div. 2) B. Anton and Classes 水题
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)-A - Bear and Three Balls-水题
- A. GukiZ and Contest-Codeforces Round #307 (Div. 2)-简单水题