codeforces282B

div2B 贪心随便爆一遍就ok了

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0; bool f=0; char ch=' ';
    while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
    while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0) {putchar('-'); x=-x;}
    if(x<10) {putchar(x+'0'); return;}
    write(x/10); putchar((x%10)+'0');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=1000005;
int n,A[N],G[N];
char wwx[N];
inline int sb(int x,int y);
int main()
{
    freopen("codeforces.in","r",stdin);
    int i,wn=0,wq=0;
    R(n);
    for(i=1;i<=n;i++)
    {
        R(A[i]); R(G[i]);
    }
    for(i=1;i<=n;i++)
    {
        if(sb(wn+A[i],wq)<sb(wn,wq+G[i]))
        {
            wn+=A[i];
            wwx[i]='A';
        }
        else
        {
            wq+=G[i];
            wwx[i]='G';
        }
        if(sb(wn,wq)>500)
        {
            puts("-1");
            return 0;
        }
    }
    for(i=1;i<=n;i++) putchar(wwx[i]); putchar('\n');
    return 0;
}
inline int sb(int x,int y)
{
    return abs(x-y);
}
View Code

 

posted @ 2021-10-25 00:12  yccdu  阅读(10)  评论(0编辑  收藏  举报