Cod sursa(job #1959366)
| Utilizator | Data | 9 aprilie 2017 13:39:49 | |
|---|---|---|---|
| Problema | Semne | Scor | 65 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#define nmax 50005
using namespace std;
ifstream f("semne.in");
ofstream g("semne.out");
long long s;
bool x[nmax];
int n,a[nmax];
int main()
{
f>>n>>s; long long sum=0;
for(int i=1;i<=n;i++){f>>a[i]; sum-=a[i];}
srand(time(0));
while(s!=sum)
{
int c=rand()%n;
if(x[c]==1)
{ x[c]=0; sum-=2*a[c+1];}
else
if(2*a[c+1]+sum<=s)
{
sum+=2*a[c+1];
x[c]=1;
}
}
for(int i=1;i<=n;i++)
if(x[i-1]==0)
g<<'-';
else
g<<'+';
return 0;
}
