Ideas:
The main attention of this question is the judgment of dictionary order.
Pits: When the two teams score exactly the same as the sequence, who voted for the last goal who wins.
AC Code:
1#include <iostream>2#include <stdio.h>3#include <algorithm>4#include <cstring>5#include <string.h>6#include <math.h>7#include <queue>8#include <stack>9#include <stdlib.h>Ten#include <map> One using namespacestd; A #defineLL Long Long - #defineSF (a) scanf ("%d",& (a)); - #defineN 500050 the CharName1[n],name2[n]; - intF1[n],f2[n]; - intt1,t2; - intflag=0; + intdeal () { - //Judge F1 and F2 dictionary order that big. + inta,b;a=b=0; A while(A<t1 && b<T2) { at - if(F1[a] = =F2[b]) { -a++;b++; - Continue; - } - Else if(F1[a]>f2[b])return 1; in Else return 0; - to } + if(T1==a && t2==b) { - if(flag==1)return 1; the Else return 0; * } $ if(t2==b)return 1;//T2 First finished T1 long, its dictionary order is larger;Panax Notoginseng return 0; - } the intMain () + { A intN//t1=t2=0; theLL num1,num2;num1=num2=0; +scanf"%d",&n); - while(n--){ $ intT; $scanf"%d",&t); - if(t>0) { -NUM1 + =T; theflag=1; -f1[t1++] =T;Wuyi } the Else{ -Num2 + = (-t); Wuflag=2; -f2[t2++] = (-t); About } $ } - if(num1>num2) printf ("first\n"); - Else if(num1<num2) printf ("second\n"); - Else{ A if(Deal ()) printf ("first\n"); + Elseprintf"second\n"); the } - return 0; $}
B. Vasya and Wrestling