Today Alex was brought array of length . He can apply as many operations as he wants (including zero operations) to change the array elements.
In operation Alex can choose any and such that , and multiply all elements of the array from to inclusive by . In other words, Alex can replace the subarray by in operation.
For example, let , the array is , and , then after the operation the array will be .
Alex is late for school, so you should help him find the maximum possible sum of numbers in the array, which can be obtained by making any number of operations, as well as the minimum number of operations that must be done for this.
输入格式
The first line contains a single integer ( ) — number of test cases. Then the descriptions of the test cases follow.
The first line of each test case contains one integer ( ) — length of the array.
The second line contains integers ( ) — elements of the array.
It is guaranteed that the sum of for all test cases does not exceed .
输出格式
For each test case output two space-separated numbers: the maximum possible sum of numbers in the array and the minimum number of operations to get this sum.
Pay attention that an answer may not fit in a standard integer type, so do not forget to use 64-bit integer type.
Below, for each test case, only one of the possible shortest sequences of operations is provided among many. There are others that have the same length and lead to the maximum sum of elements.
In the first test case, Alex can make operations: , , .
In the second test case, to get the largest sum you need to make operations: , .
In the fourth test case, it is necessary to make only one operation: .
////Long Long#include <bits/stdc++.h>
#define int long long
usingnamespace std;
constint N=1e6+10,mod=1e9+7;
string s;
int n,t,a[N],f[N],res,num,ans,m;
bool vis[N];
signed main()
{
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n;
res=0,ans=0;
bool f=false;
for(int i=0;i<n;i++){
cin>>m;
ans+=abs(m);
if(m<0&&!f) res++,f=true;
elseif(m==0&&f) continue;
elseif(m>0&&f) f=false;
}
cout<<ans<<""<<res<<endl;
}
return0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)