1400B - RPG Protagonist - CodeForces Solution


brute force greedy math *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int modd = 114514;
const int N = 1919810;
int n,t,m;

void solve(){
	ll ap1,ap2,num1,num2,dam1,dam2;
	cin >> ap1 >> ap2 >> num1 >> num2 >> dam1 >> dam2;
	if(dam1 > dam2){
		swap(dam1,dam2);
		swap(num1,num2);
	}
	ll ans = 0;
	for(ll i = 0; i <= num1; i ++){
		ll used1 = i;
		ll yushu1 = ap1 - i*dam1;
		if(yushu1 < 0) break;
		ll used2 = min(num2,yushu1/dam2);
		yushu1 -= used2*dam2;
		ll nownum1 = num1 - used1;
		ll nownum2 = num2 - used2;
		ll used1_ = min(nownum1,ap2/dam1);
		ll yushu2 = ap2 - used1_*dam1;
		ll used2_ = min(nownum2,yushu2/dam2);
		ll num = used1 + used2 + used1_ + used2_;
		ans = max(ans,num);
	}
	cout << ans << '\n';
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> t;
	while(t --){
		solve();
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

1041D - Glider
1486A - Shifting Stacks
1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars
1538E - Funny Substrings
234A - Lefthanders and Righthanders
1611D - Weights Assignment For Tree Edges
197A - Plate Game
1474A - Puzzle From the Future
6B - President's Office
1405B - Array Cancellation
431C - k-Tree
101A - Homework
1642C - Great Sequence
1523B - Lord of the Values
1406C - Link Cut Centroids
2409. Count Days Spent Together
2410. Maximum Matching of Players With Trainers
1604C - Di-visible Confusion
997A - Convert to Ones
218A - Mountain Scenery
486B - OR in Matrix
1405A - Permutation Forgery
1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess