fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. //#include <ext/pb_ds/assoc_container.hpp> // Common file
  4. //#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  5. //using namespace __gnu_pbds; // order of key(keys strictly less than) // find_by_order
  6. //typedef tree<long long,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
  7. //typedef tree<long long, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
  8. //IF WA CHECK FOR : -
  9. // 1 > EDGE CASES LIKE N=1 , N=0
  10. // 2 > SIGNED INTEGER OVERFLOW IN MOD
  11. // 3 > CHECK THE CODE FOR LOGICAL ERRORS AND SEG FAULTS
  12. // 4 > READ THE PS ONCE AGAIN , if having double diff less than 1e-8 is same.
  13. // 5 > You Have got AC .
  14. #define ll long long
  15. #define NUM (ll)998244353
  16. #define inf (long long)(2e18)
  17. #define ff first
  18. #define ss second
  19. #define f(i,a,b) for(ll i=a;(i)<long(b);(i)++)
  20. #define fr(i,a,b) for(ll i=a;(i)>=(long long)(b);(i)--)
  21. #define it(b) for(auto &it:(b))
  22. #define pb push_back
  23. #define mp make_pair
  24. typedef vector<ll> vll;
  25. typedef pair<ll,ll> pll;
  26. ll binpow( ll base , ll ex,ll mod=NUM) {
  27. ll ans = 1;base = base % mod;
  28. if(base==0){
  29. return 0;
  30. }
  31. while (ex > 0) {
  32. if (ex % 2 == 1) {
  33. ans = (ans * base) % mod;
  34. }
  35. base = (base * base) % mod;
  36. ex = ex / 2;
  37. }
  38. return ans;
  39. }
  40. void read(vll &arr,ll n) {
  41. if (arr.size() != n) { arr.assign(n, 0); }for (int i = 0; i < n; i++)cin >> arr[i];
  42. }
  43. inline ll min(ll a,ll b){
  44. if(a>b)return b;return a;
  45. }
  46. inline ll max(ll a, ll b){
  47. if(a>b)return a;return b;
  48. }
  49. inline ll dif(ll a,ll b) {
  50. if (a > b)return a - b;return b - a;
  51. }
  52. long long gcd(long long a,long long b) {
  53. if (b == 0)return a;return gcd(b, a % b);
  54. }
  55. long long lcm(long long a,long long b) {
  56. long long k = gcd(a, b);
  57. return (a * b) / k;
  58. }
  59. void solve() {
  60. ll n,m;
  61. cin>>n>>m;
  62. vector<ll> a;read(a,n+1);
  63. vector<ll>c(n+m+1);read(c,n+m+1);
  64. vector<ll> b(m+1);
  65. b[0]=c[0]/a[0];
  66. f(j,1,m+1){
  67. ll curr = c[j];
  68. f(k,0,j){
  69. if(j-k>=a.size() or k>=b.size()){
  70. continue;
  71. }
  72. curr-=(b[k]*a[j-k]);
  73. }
  74. b[j]=curr/a[0];
  75. }
  76. f(i,0,m){
  77. cout<<b[i]<<" ";
  78. }
  79. cout<<b[m];
  80. cout<<"\n";
  81. }
  82. int main() {
  83. ios_base::sync_with_stdio(false);
  84. cin.tie(NULL);
  85. cout << fixed << showpoint;
  86. cout << setprecision(12);
  87. long long test_m = 1;
  88. int k=1;
  89. //cin >> test_m;
  90. //WE WILL WIN .
  91. while (test_m--) {
  92. //cout<<"Case #"<<k++<<": ";
  93. solve();
  94. }
  95. }
Runtime error #stdin #stdout #stderr 0s 5380KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc