Cod sursa(job #2250470)

Utilizator razvanboabesrazvan boabes razvanboabes Data 30 septembrie 2018 14:14:42
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("valoare.in");
ofstream out("valoare.out");
struct vec {
    int val,poz;
};
int v[50005];
vec p2[50005];
int sume[50005];
int main() {
    int n,putere=1,cnt=0,i,j,cj,cop,xcnt;
    unsigned long long s;
    in>>n;
    for(i=0; i<n; i++)
        in>>v[i];
    sort(v,v+n);
    for(i=0; i<n; i++) {
        if(v[i]==putere) {
            cop=v[i];
            xcnt=i;
            while(v[xcnt]==cop) {
                p2[cnt].val=v[xcnt];
                v[xcnt]*=-1;
                p2[cnt++].poz=xcnt;
                xcnt++;
            }
            putere*=2;
            i=xcnt-1;
        }
    }
    s=0;
    sort(v,v+n);
    for(j=0; j<n and j<cnt; j++) {
        s+=p2[j].val;
        out<<s<<'\n';
    }
    int vmax;
    if(v[0]<0){
        int x=0,s1=0;;
            while(v[x]==v[0]){
                s1+=v[x]*-1;
                x++;
            }
        vmax=s1*2-1;
    }
    else vmax=-1;
    n--;
    int cn=n;
//    for(j=n; j>=cnt; j--) {
//        cj=j;
//        if(vmax==-1)
//            out<<0<<'\n';
//        else {
//            s+=v[cj];
//            v[cj]=0;
//        }
//        out<<s<<'\n';
//    }
   for(i=cnt; i<=n; i++){
        if(v[i]<=s+1)
          s+=v[i];
            out<<s<<'\n';
    }
    return 0;
}