Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n, d, mi = 0, ma = 0;
  10.     cin >> n >> d;
  11.     vector<vector<int>> a(n,2);
  12.     vector <int> b(n);
  13.     for (int i = 0; i < n; i++)
  14.     {
  15.         cin >> a[i][0] >> a[i][1];
  16.         mi = mi + a[i][0];
  17.         ma = ma + a[i][1];
  18.     }
  19.     if ((mi <= d) && (ma >= d))
  20.     {
  21.         cout << "YES" << endl;
  22.         for (int i = 0; i < n; i++)
  23.         {
  24.             b[i] = a[i][1];
  25.             d = d - a[i][1];
  26.         }
  27.         int j = 0;
  28.         while(d != 0)
  29.         {
  30.             b[j] = max(a[j][0], a[j][1] + d);
  31.             d = d + a[j][1] - b[j];
  32.             j++;
  33.         }
  34.         for (int i = 0; i < n; i++)
  35.             cout << b[i] << " ";
  36.     }
  37.     else
  38.         cout << "NO";  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement