Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- long long n, s;
- cin >> n >> s;
- long long d[n];
- long long r[n];
- long long e[n]; ///Elegible
- s--;
- for(int i=0; i<n; i++)
- {
- e[i] = 1;
- r[i] = 1;
- cin >> d[i];
- s-=d[i];
- }
- ///Ahora los reparto como pueda
- if(s == 0)
- {
- for(int i=0; i<n; i++)
- cout << 1 << " ";
- cout << endl;
- return 0;
- }
- for(int i=0; i<n; i++)
- {
- int mayor = 1;
- int pos = 0;
- for(int j=0; j<n; j++)
- {
- if(e[j] && mayor < d[j])
- {
- mayor = d[j];
- pos = j;
- }
- }
- e[pos] = false;
- while(r[i] < 1000 && s >= d[pos])
- {
- r[i]++;
- s-=d[pos];
- }
- }
- if(s == 0)
- {
- for(int i=0; i<n; i++)
- cout << r[i] << " ";
- cout << endl;
- return 0;
- }
- ///Busco la pos del 1
- for(int i=0; i<n; i++)
- {
- if(d[i] == 1)
- {
- long long canTake = min(1000-r[i], s);
- s -= canTake;
- r[i] += canTake;
- }
- }
- for(int i=0; i<n; i++)
- cout << r[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment