Ankit_132

F

Sep 23rd, 2023
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7.  
  8. int main()
  9. {
  10.     int MOD = 998244353;
  11.  
  12.     int q, k;
  13.     cin>>q>>k;
  14.  
  15.     vector<ll int> ways(5100);
  16.     ways[0] = 1;
  17.  
  18.     while(q--)
  19.     {
  20.         char ch;
  21.         int x;
  22.         cin>>ch>>x;
  23.  
  24.         if(ch == '+')
  25.             for(int i=k-x; i>=0; i--)       (ways[i+x] += ways[i]) %= MOD;
  26.         if(ch == '-')
  27.             for(int i=0; i<=k-x; i++)       (ways[i+x] += (MOD-ways[i])) %= MOD;
  28.  
  29.         cout<<ways[k]<<"\n";
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment