shek_shek

http://codeforces.ru/problemset/problem/489/C

Nov 27th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stack>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <string>
  8. #include <set>
  9. #include <iomanip>
  10. #include <vector>
  11. #include <map>
  12. #include <cassert>
  13. #include <queue>
  14. #include <tuple>
  15.  
  16. using namespace std;
  17.  
  18. typedef long long ll;
  19. typedef long double ld;
  20.  
  21. #define forn(i, n) for (int i = 0; i < int(n); ++i)
  22. #define pb push_back
  23. #define mp make_pair
  24. #define shek_shek _DEBUG
  25. #define all(v) v.begin(),v.end()
  26. #define EPS 1e-9
  27. #define PI 3.1415926535897932384626433832795
  28. const int N = 150000;
  29.  
  30. int a[N];
  31. long long sum[N + 1];
  32.  
  33.  
  34. int main () {
  35.     int m, s;
  36.     cin >> m >> s;
  37.     if ((s == 0 && m > 1) ||
  38.         (s > m * (s >= 10 ? 9 : s - 1))){
  39.             cout << -1 << " " << -1;
  40.             return 0;
  41.     }
  42.     int minsum = 0, maxsum = 0;
  43.  
  44.     string min_ans = "";
  45.  
  46.     for (int i = m - 1; i >= 0; i--) {
  47.         if (s - minsum >= (s >= 10 ? 10 : s)) {
  48.             min_ans += (s >= 10 ? '9' : (char)('0' + s - 1));
  49.             minsum += (s >= 10 ? 9 : s - 1);
  50.         } else {
  51.             if (i > 0) {  
  52.                 if (minsum == s - 1) {
  53.                     min_ans += '0';
  54.                 } else {            
  55.                     min_ans += (char)('0' + (s - minsum) - 1);
  56.                     minsum = s - 1;
  57.                 }
  58.             } else {
  59.                 min_ans += (char)('0' + (s - minsum));
  60.             }
  61.         }
  62.     }
  63.     reverse(all(min_ans));
  64.     cout << min_ans;
  65.     cout << " ";
  66.     forn (i, m) {
  67.         if (s - maxsum >= 10) {
  68.             cout << 9;
  69.             maxsum += 9;
  70.         } else {
  71.             cout << s - maxsum;
  72.             maxsum += s - maxsum;
  73.         }
  74.     }
  75.  
  76.  
  77.  
  78.         return 0;
  79. }
Add Comment
Please, Sign In to add comment