牛客网暑期ACM多校训练营(第二场)D money

4. White Cloud has built n stores numbered from 1 to n. White Rabbit wants to visit these stores in the order from 1 to n. The store numbered i has a price a[i] representing that White Rabbit can spend a[i] dollars to buy a product or sell a product to get a[i] dollars when it is in the i-th store. The product is too heavy so that White Rabbit can only take one product at the same time. White Rabbit wants to know the maximum profit after visiting all stores. Also, White Rabbit wants to know the minimum number of transactions while geting the maximum profit. Notice that White Rabbit has infinite money initially.

输入描述:

The first line contains an integer T(0

输出描述:

For each test case, print a single line containing 2 integers, denoting the maximum profit and the minimum number of transactions.

示例1:

输入

1
5

9 10 7 6 8

输出

3 4

#include "bits/stdc++.h"
#define maxx 100005
#define LL long long
using namespace std;
LL a[maxx];
int main(){
    int T;
    cin>>T;
    while(T--){
        LL n,f,sum=0,mon=0,num=0;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++){
                int f=i;
            for(int j=i+1;j<=n;j++,f++){
                if(a[j]>=a[f]){
                    sum=a[j]-a[i];
                }
                if(a[j]

各个不下降子序列最后一个元素减第一个元素的和

你可能感兴趣的:(牛客网题目)