Codeforces Round #556 (Div. 2) A题

题面很简单,思路就是简单贪心,si数组是贮存购买数组,bi数组是贮存出售数组,题面是给你r的货币,让你通过出售和购买来获取最大价值,第一种算法是通过找出bi数组最大值,和si数组最小值,通过比较来计算最大值,如果bi数组最大值小于了si数组最小值,说明购买无意义,反之只要计算能买多少只si数组的股票,去出售bi数组的最大值换去收益。接下来是代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 10010;
int main()
{
 int n, m, r;
 int a[maxn], b[maxn];
 cin >> n >> m >> r;
 for (int i = 0; i < n; i++)
 {
  scanf("%d", &a[i]);
 }
 for (int i = 0; i < m; i++)
 {
  scanf("%d", &b[i]);
 }
 sort(a, a + n);
 sort(b, b + m);
 if (a[0] >= b[m - 1])
 {
  printf("%d ", r);
 }
 else
 {
  int sum = 0;
  int x = r % a[0];
  sum = x + r / a[0] * b[m - 1];
  cout << sum << endl;
 }
}

原文地址:https://www.cnblogs.com/csxaxx/p/10800458.html