Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
- #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " " << s << "\n";
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
- #define fixed(n) fixed << setprecision(n)
- #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define fill(vec, value) memset(vec, value, sizeof(vec));
- #define Num_of_Digits(n) ((int)log10(n) + 1)
- #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
- #define all(vec) vec.begin(), vec.end()
- #define rall(vec) vec.rbegin(), vec.rend()
- #define sz(x) int(x.size())
- #define debug(x) cout << #x << ": " << (x) << "\n";
- #define fi first
- #define se second
- #define Pair pair < int, int >
- #define ll long long
- #define ull unsigned long long
- #define Mod 1'000'000'007
- #define OO 2'000'000'000
- #define EPS 1e-9
- #define PI acos(-1)
- template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
- for (auto &x: v) in >> x;
- return in;
- }
- template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
- for (const T &x: v) out << x << ' ';
- return out;
- }
- void AhMeD_HoSSaM(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- freopen("tank.in", "r", stdin);
- /*#ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif*/
- }
- ll n, S, T;
- vector < ll > dp1;
- vector < pair < ll, ll > > dp2;
- ll min_water(ll curr_water){
- if(curr_water >= n) return 0;
- ll& ret = dp1[curr_water];
- if(~ret) return ret;
- ret = LLONG_MAX;
- ret = min(ret, S + min_water(curr_water + S));
- ret = min(ret, T + min_water(curr_water + T));
- return ret;
- }
- pair < ll, ll > operator + (const pair < ll, ll > &a, const pair < ll, ll > &b){
- return {a.fi + b.fi, a.se + b.se};
- }
- pair < ll, ll > min(const pair < ll, ll > &a, const pair < ll, ll > &b){
- return a.fi + a.se <= b.fi + b.se ? a : b;
- }
- pair < ll, ll > get_ans(ll water){
- if(water < 0) return {OO, OO};
- if(water == 0) return {0, 0};
- pair < ll, ll >& ret = dp2[water];
- if(ret.first != -1 && ret.second != -1) return ret;
- ret = {OO, OO};
- ret = min(ret, make_pair(1, 0) + get_ans(water - S));
- ret = min(ret, make_pair(0, 1) + get_ans(water - T));
- return ret;
- }
- void Solve(){
- cin >> n >> S >> T;
- dp1.assign(n + max(S, T) + 10, -1);
- dp2.assign(n + max(S, T) + 10, make_pair(-1, -1));
- ll min_wasted_water = min_water(0);
- auto [min_S, min_T] = get_ans(min_wasted_water);
- cout << min_S << ' ' << min_T << "\n";
- }
- int main(){
- AhMeD_HoSSaM();
- int t = 1;
- cin >> t;
- while(t--)
- Solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment