D-money

链接:https://www.nowcoder.com/acm/contest/140/D
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

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<T<=5), denoting the number of test cases.
In each test case, there is one integer n(0<n<=100000) in the first line,denoting the number of stores.
For the next line, There are n integers in range [0,2147483648), denoting a[1..n].

输出描述:

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

输入例子:
1
5
9 10 7 6 8
输出例子:
3 4

-->

示例1

输入

复制

1
5
9 10 7 6 8

输出

复制

3 4
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define MAX 100005
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll; int a[MAX],dpg[MAX][];
ll dpf[MAX][]; int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&a[i]);
}
memset(dpf,,sizeof(dpf));
memset(dpg,,sizeof(dpg));
dpf[][]=;
dpf[][]=-a[];
dpg[][]=;
dpg[][]=;
for(i=;i<=n;i++){
if(dpf[i-][]>=dpf[i-][]+a[i]){
dpf[i][]=dpf[i-][];
dpg[i][]=dpg[i-][];
}
else{
dpf[i][]=dpf[i-][]+a[i];
dpg[i][]=dpg[i-][]+;
}
if(dpf[i-][]-a[i]>dpf[i-][]){
dpf[i][]=dpf[i-][]-a[i];
dpg[i][]=dpg[i-][]+;
}
else{
dpf[i][]=dpf[i-][];
dpg[i][]=dpg[i-][];
}
}
printf("%lld %d\n",dpf[n][],dpg[n][]);
}
return ;
}

最新文章

  1. @helper函数使用方法
  2. echarts一个页面动态加载两张不同图表数据
  3. Uri.AbsoluteUri 与 Uri.ToString() 的区别
  4. 迭代器iterator(三):Listlterator遍历arraylist,并用逆序输出结果
  5. js运动
  6. RTTI(Runtime Type Information )
  7. IE兼容性问题
  8. linux命令打开程序
  9. Maven+struts2+spring4+hibernate4的环境搭建
  10. Linux(4)系统管理
  11. vue.js基础知识篇(1):简介、数据绑定
  12. 学习js函数--自执行函数
  13. hdu 5002 (动态树lct)
  14. Centos7 设置vim 显示文本不同颜色
  15. Java z 404
  16. 机器学习sklearn
  17. Linux—CentOS7下python开发环境配置
  18. IntelliJ IDEA 中SpringBoot对Run/Debug Configurations配置 SpringBoot热部署
  19. System类的使用
  20. The Road to Ryu: Hi Ryu

热门文章

  1. Linq Group By 多个字段
  2. vue element-ui 自动获取光标
  3. leetcode 890. Possible Bipartition
  4. manacher小结
  5. ios图片瀑布流代码
  6. Use trained sklearn model with pyspark
  7. memcached高可用
  8. 跨线程send message
  9. 第六章-jQuery
  10. CodeForces -163E :e-Government (AC自动机+DFS序+树状数组)