Page 1 of 1

1614 - Hell on the Markets

Posted: Mon Jul 21, 2014 10:43 am
by 12061160

Code: Select all

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
#define v first
#define pos second

typedef pair<int,int> p;
p s[100005];
bool ans[100005];
int n;

bool cmp(p a,p b)
{
    return a.v > b.v;
}
int main() {
    while(~RD(n)) {
        int sum = 0;
        clr0(ans);
        for(int i = 0;i < n;++i){
            RD(s[i].v);
            s[i].pos = i;
            sum += s[i].v;
        }
        if(sum&1)
            puts("No");
        else{
            puts("Yes");
            sum /= 2;
            sort(s,s+n,cmp);
            for(int i = 0;i < n;++i){
                if(!sum)
                    break;
                if(sum >= s[i].v)
                    sum -= s[i].v,ans[s[i].pos] = true;
            }
            for(int i = 0;i < n;++i){
                if(ans[i])
                    printf("1 ");
                else
                    printf("-1 ");
            }
            puts("");
        }
    }
}
still get stuck...can anyone give me some help? :oops: :oops:

Re: 1614-Hell on the Markets

Posted: Mon Jul 21, 2014 11:23 am
by 12061160
got AC...
just change to long long type..