CodeForces 493B Vasya and Wrestling [simulation], codeforces493b

Source: Internet
Author: User
Tags integer numbers

CodeForces 493B Vasya and Wrestling [simulation], codeforces493b
B. Vasya and Wrestlingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 has med the last technique wins. Your task is to determine which wrestler won.

Input

The first line contains numberN-The number of techniques that the wrestlers have used (1 hour ≤ hourNLimit ≤ limit 2-105 ).

The followingNLines contain integer numbersAI(|AI| Limit ≤ limit 109,AI  =0 0). IfAIIs positive, that means that the first wrestler was med the technique that was awardedAIPoints. And ifAIIs negative, that means that the second wrestler was med the technique that was awarded (-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
512-3-43
Output
second
Input
3-1-23
Output
first
Input
24-4
Output
second
Note

SequenceXRequired bytes = required bytesX1X2...X|X| Is lexicographically larger than sequenceYRequired bytes = required bytesY1Y2...Y|Y|, If either |X| Commandid> commandid |Y| AndX1 worker = workerY1. zookeeper,X2 bytes consumed = bytes consumedY2, please..., please wait ,...,X|Y| Commandid = commandidY|Y|, Or there is such numberR(RCommandid <commandid |X|, Bytes,RCommandid <commandid |Y|), ThatX1 worker = workerY1. zookeeper,X2 bytes consumed = bytes consumedY2, please wait..., please wait ,...,XRRequired bytes = required bytesYRAndXRZookeeper + zookeeper 1 zookeeper> zookeeperYRRequired bytes + required bytes 1.

We use notation |A| To denote length of sequenceA.

Be sure to make sure that it will cross the border !!!!

Code:

#include <stdio.h>#include <string.h>#define M 250050typedef 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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.