Guest User

Untitled

a guest
May 25th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <iomanip>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <algorithm>
  8. #include <queue>
  9. #include <stack>
  10. #include <set>
  11. #include <map>
  12. #include <list>
  13. #include <vector>
  14. #include <string>
  15. #include <cstring>
  16. #include <cmath>
  17. #include <ctime>
  18. #include <cassert>
  19.  
  20. using namespace std;
  21.  
  22. #define forn(i, n) for(int i = 0; i < (int)(n); i++)
  23. #define forn1(i, n) for(int i = 1; i <= (int)(n); i++)
  24. #define all(a) (a).begin(), (a).end()
  25. #define sz(a) (int)((a).size())
  26. #define mp make_pair
  27. #define pb push_back
  28. #define X first
  29. #define Y second
  30. #define x first
  31. #define y second
  32. #define y1 __y1
  33. #define sqr(x) ((x) * (x))
  34.  
  35. typedef long long li;
  36. typedef long double ld;
  37. typedef pair<int, int> pt;
  38.  
  39. const int INF = (int)(1e9);
  40. const li INF64 = (li)(INF) * (li)(INF);
  41. const ld eps = 1e-9;
  42. const ld pi = ld(3.1415926535897932384626433832795);
  43.  
  44. bool in(int i, int j, int n, int m)
  45. {
  46.     return i >= 1 && i <= n && j >= 1 && j <= m;
  47. }
  48.  
  49. inline int myrand()
  50. {
  51.     return (rand() ^ (rand() << 15));
  52. }
  53.  
  54. const int dx[] = {-1, 1, 1, -1};
  55. const int dy[] = {1, 1, -1, -1};
  56.  
  57. const int N = 1111;
  58.  
  59. int a[N];
  60. int n, m;
  61. int s = 0;
  62.  
  63. inline bool read()
  64. {
  65.     if(!(cin >> n >> m))
  66.         return false;
  67.  
  68.     forn(i, n)
  69.     {
  70.         assert(cin >> a[i]);
  71.         s += a[i];
  72.     }
  73.  
  74.     return true;
  75. }
  76.  
  77. inline void solve()
  78. {
  79.     for(int cnt = n; ; cnt++)
  80.     {
  81.         int ans = cnt - n;
  82.         int need = m * cnt;
  83.         need -= s;
  84.         if(need < 0)
  85.             continue;
  86.         int lf = ans, rg = ans * 10;
  87.         if(lf <= need && need <= rg)
  88.         {
  89.             cout << ans << endl;
  90.             vector<int> res;
  91.             int sum = need;
  92.             while(ans > 0)
  93.             {
  94.                 int c = -1;
  95.                 for(int cur = 1; cur <= 10; cur++)
  96.                 {
  97.                     int ost = sum - cur;
  98.                     if(ans - 1 <= ost && ost <= (ans - 1) * 10)
  99.                     {
  100.                         c = cur;
  101.                         break;
  102.                     }
  103.                 }
  104.  
  105.                 assert(c >= 1 && c <= 10);
  106.                 res.pb(c);
  107.                 ans--;
  108.                 sum -= c;
  109.             }
  110.  
  111.             assert(sum == 0 && ans == 0);
  112.             forn(i, sz(res))
  113.                 cout << res[i] << ' ';
  114.             cout << endl;
  115.             return;
  116.         }
  117.     }
  118.  
  119.     return;
  120. }
  121.  
  122. int main(){
  123. #ifdef _DEBUG
  124.     assert(freopen("input.txt", "rt", stdin));
  125.     assert(freopen("output.txt", "wt", stdout));
  126. #endif
  127.  
  128.     cout << setprecision(10) << fixed;
  129.     cerr << setprecision(10) << fixed;
  130.  
  131.     srand(int(time(NULL)));
  132.  
  133.     assert(read());
  134.     solve();
  135.  
  136.     cerr << "TIME == " << clock() << " ms" << endl;
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment