문제
https://codeforces.com/contest/1150/problem/A
Problem - A - Codeforces
codeforces.com
풀이
가장 저렴하게 구매해서, 가장 비싸게 파는 것이 유리하다.
$smin=\min(s_i)$와 $bmax=\max(b_i)$를 구하자.
가능한 만큼, $smin$원에 구매하고, $smax$원에 판매하면 된다.
Time Complexity : $O(n+m)$
코드
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,r,x;
	int smin=10000,bmax=0;
	cin>>n>>m>>r;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(smin>x)smin=x;
	}
	for(int i=0;i<m;i++)
	{
		cin>>x;
		if(bmax<x)bmax=x;
	}
	if(smin>=bmax) cout<<r;
	else cout<<(r/smin)*bmax+r%smin;
}
'PS > codeforces' 카테고리의 다른 글
| [codeforces] 1150E. Tree Generator™ (0) | 2019.05.01 | 
|---|---|
| [codeforces] 1150D. Three Religions (0) | 2019.04.30 | 
| [codeforces] 1150C. Prefix Sum Primes (0) | 2019.04.30 | 
| [codeforces] 1150B. Tiling Challenge (0) | 2019.04.30 |