「CF493B」Vasya and Wrestling
题解
先判断和的符号
再比较字典序,用两个指针从左往右扫
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include<map> #include<set> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000007 #define inf 1000000000 using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ll sum; string last; int n; int t1,t2; int a[200005],b[200005]; int main() { n=read(); for(int i=1;i<=n;i++) { int x=read();sum+=x; if(x>0)a[++t1]=x,last="first"; else b[++t2]=-x,last="second"; } if(sum>0)puts("first"); else if(sum<0)puts("second"); else { int l1=1,l2=1; while(l1<=t1&&l2<=t2) { if(a[l1]>b[l2]){puts("first");return 0;} else if(a[l1]<b[l2]){puts("second");return 0;} l1++;l2++; } if(l1<t1)puts("second"); else if(l2<t2)puts("first"); else cout<<last; } return 0; } |
Subscribe