Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n, x, z;
- cin>>n>>x>>z;
- vector<int> a(n);
- for(auto &e: a)
- cin>>e;
- if(z%x == 0)
- {
- cout<<z/x<<"\n";
- continue;
- }
- int rem = x - z%x;
- vector<ll int> mmin1(x+1, 1e18);
- vector<ll int> mmin2(x+1, 1e18);
- mmin1[0] = 0;
- for(auto e: a)
- {
- for(int i=0; i<x; i++)
- mmin2[(i+e)%x] = min(mmin2[(i+e)%x], mmin1[i]+e);
- for(int i=0; i<x; i++)
- mmin1[i] = min(mmin1[i], mmin2[i]);
- fill(mmin2.begin(), mmin2.end(), 1e18);
- }
- if(mmin1[rem] == 1e18)
- cout<<"-1\n";
- else
- cout<<(z+mmin1[rem])/x<<"\n";
- }
- }
Advertisement
Comments
-
- valorant skin changer
- https://www.youtube.com/watch?v=NNqGm3ZclZM
Add Comment
Please, Sign In to add comment
Advertisement