Gym - 100541A

链接:http://codeforces.com/gym/100541/problem/A
An expert in deep learning has developed a new method for stock market forecasting. According to his method, the forecasted stock prices of VAIP for the next N days are p1, p2, p3, …, pN, where pi denotes the forecasted stock price for the ith day.

Given pi and the total amount of money W, find a way to buy and sell VAIP stocks to maximize the profit. You can only buy VAIP stocks in one day, or you don’t buy at all. The number of stocks bought or sold must be an integer.

Input
The input file consists of several datasets. The first line of the input file contains the number of datasets which is a positive integer and is not greater than 10. The following lines describe the datasets.

Each dataset consists of two lines where the first line contains two space-separated integers N (N ≤ 100) and W (0 < W ≤ 1, 000, 000) where W is the amount of money you will invest in the stock. The second line contains N space-separated integers representing pi (0 < pi ≤ 1000).

Output
For each dataset, write out on one line the maximum profit you could make.

Examples
Input
1
12 1000000
99 100 101 102 100 99 97 101 102 105 104 104
Output
82472
Note
You should buy 10309 (=1000000 div 97) stocks at the price of 97 and sell 10309 stocks at the price of 105 to get the maximum profit of (105-97)*10309

只能存一次,没看见,很烦

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
   
    int T;
    cin>>T;
    while(T--)
    {
        int a,b;
        cin>>a>>b;
        int shu[105];
        for(int i=1;i<=a;i++)
            cin>>shu[i];
        long long yu=0,w=0,sum=0,sum2=0;
        for(int i=1;i<a;i++)
        {
             yu=b%shu[i];
             w=b/shu[i];
            for(int j=i+1;j<=a;j++)
            {
                sum=yu+shu[j]*w;
                if(sum>sum2) sum2=sum;

            }

        }
        if(sum2>=b) cout<<sum2-b<<endl;
            else cout<<"0"<<endl;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值