Advertisement
Ahmed_Negm

H

Jun 2nd, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<iomanip>
  5. #include<algorithm>
  6. #include<cstdlib>
  7. #include<cstring>
  8. #include<vector>
  9. #include<utility>
  10. using namespace std;
  11.  
  12. #define ll long long
  13. #define nl '\n'
  14. #define sz(x) int(x.size())
  15. #define all(x) x.begin(),x.end()
  16. #define rall(s)  s.rbegin(), s.rend()
  17. #define getline(s) getline(cin>>ws,s)
  18. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  19. #define pi  3.141592653589793
  20.  
  21. /*
  22. ███╗░░██╗███████╗░██████╗░███╗░░░███╗
  23. ████╗░██║██╔════╝██╔════╝░████╗░████║
  24. ██╔██╗██║█████╗░░██║░░██╗░██╔████╔██║
  25. ██║╚████║██╔══╝░░██║░░╚██╗██║╚██╔╝██║
  26. ██║░╚███║███████╗╚██████╔╝██║░╚═╝░██║
  27. ╚═╝░░╚══╝╚══════╝░╚═════╝░╚═╝░░░░░╚═╝
  28.  
  29. */
  30.  
  31. void Fast_IO(){
  32. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  33. // freopen("filename.in", "r", stdin);
  34. #ifndef ONLINE_JUDGE
  35. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  36. #endif
  37. }
  38.  
  39.  
  40.  
  41.  
  42. void solve(){
  43. ll n,s; cin>>n>>s;
  44. vector<ll>v(n);
  45. ll start =9;
  46. if((s>n*9) or (s%2== 1 and n%2 ==0)) return void (cout<<-1<<nl);
  47. int l=0,r=n-1, mid = n/2;
  48. while(s>0){
  49.     if(s - 2*start< 0) start--;
  50.     else{  
  51.         s -= 2*start;
  52.         v[l++] = start;
  53.         v[r--] = start;
  54.     }
  55.     if(l>=r) break;
  56. }  
  57.  
  58.  
  59. if(s>=0 and s <=9 and n%2){
  60.      v[mid] = s;
  61.      s=0;
  62. }
  63.  
  64. if(v[0] == 0) return void(cout<<-1<<nl);
  65. if(s == 0){
  66.     for(auto i:v) cout<<i;
  67.     cout<<nl;
  68.     return;
  69. }else return void (cout<<-1<<nl);
  70.  
  71.  
  72.  
  73.  
  74. }
  75.  
  76. int main(){
  77.     Fast_IO();
  78. int t =1;
  79. cin>>t;
  80. while(t--){
  81. solve();
  82. }
  83. return 0;
  84. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement