https://codeforces.com/contest/1409
Dashboard - Codeforces Round #667 (Div. 3) - Codeforces
codeforces.com
[난이도] Div.3
[유형] 구현
[풀이]
axb가 작아지려면 a와 b의 차이가 크게 날수록 작아진다.
n을 a에서 먼저 뺄수 있을 만큼 빼주고 b에서 뺄 수 있을 만큼 빼준값과
n을 b에서 먼저 뺄수 있을 만큼 빼주고 a에서 뺄 수 있을 만큼 빼준값을
비교해서 더 작은 값을 정답으로 하면 된다.
#include <cstdio> #include <algorithm> using namespace std; using ll = long long; int tc; ll a,b,x,y,n,ret; ll sol(){ ll ans,tn; if(a-x>=n){ ans = (a-n)*b; }else{ tn = n-(a-x); ans = x*max(y,b-tn); } return ans; } int main(){ scanf("%d",&tc); while(tc--){ scanf("%d%d%d%d%d",&a,&b,&x,&y,&n); ret = sol(); swap(a,b); swap(x,y); ret = min(ret,sol()); printf("%lld\n",ret); } }
https://github.com/has2/Problem-Solving/blob/master/codeforces/Round667-Div.3/B.cpp