[ABC100D] Patisserie ABC

这篇具有很好参考价值的文章主要介绍了[ABC100D] Patisserie ABC。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Problem Statement

Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100.

The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i-th kind of cake has the beauty of xi​, the tastiness of yi​ and the popularity of zi​.
These values may be zero or negative.

Ringo has decided to have M pieces of cakes here. He will choose the set of cakes as follows:

  • Do not have two or more pieces of the same kind of cake.
  • Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).

Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.

Constraints

  • N is an integer between 11 and 1 0001 000 (inclusive).
  • M is an integer between 00 and N (inclusive).
  • xi​,yi​,zi​ (1≤i≤N) are integers between −10 000 000 000−10 000 000 000 and 10 000 000 00010 000 000 000 (inclusive).

Input

Input is given from Standard Input in the following format:

N M
1x1​ 1y1​ 1z1​
2x2​ 2y2​ 2z2​
 ::  ::
xN​ yN​ zN​

Output

Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.


Sample Input 1 Copy

Copy

5 3
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9

Sample Output 1 Copy

Copy

56

Consider having the 22-nd, 44-th and 55-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:

  • Beauty: 1+3+9=13
  • Tastiness: 5+5+7=17
  • Popularity: 9+8+9=26

The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 13+17+26=5613+17+26=56. This is the maximum value.


Sample Input 2 Copy

Copy

5 3
1 -2 3
-4 5 -6
7 -8 -9
-10 11 -12
13 -14 15

Sample Output 2 Copy

Copy

54

Consider having the 11-st, 33-rd and 55-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:

  • Beauty: 1+7+13=21
  • Tastiness: (−2)+(−8)+(−14)=−24
  • Popularity: 3+(−9)+15=9

The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 21+24+9=54. This is the maximum value.


Sample Input 3 Copy

Copy

10 5
10 -80 21
23 8 38
-94 28 11
-26 -2 18
-69 72 79
-26 -86 -54
-72 -50 59
21 65 -32
40 -94 87
-62 18 82

Sample Output 3 Copy

Copy

638

If we have the 3-rd, 4th, 5-th, 7-th and 10-th kinds of cakes, the total beauty, tastiness and popularity will be −323, 66 and 249, respectively.
The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 323+66+249=638. This is the maximum value.


Sample Input 4 Copy

Copy

3 2
2000000000 -9000000000 4000000000
7000000000 -5000000000 3000000000
6000000000 -1000000000 8000000000

Sample Output 4 Copy

Copy

30000000000

The values of the beauty, tastiness and popularity of the cakes and the value to be printed may not fit into 32-bit integers.

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int,int>PII;
constexpr int N = 2,mod=1e9+7;

struct node{
    int a,b,c;
}p[1005];
int i,j,k;
bool cmp(node a,node b){
    return a.a*i+a.b*j+a.c*k>b.a*i+b.b*j+b.c*k;
}
signed main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,m;
    cin>>n>>m;
    for( i=1;i<=n;i++){
        cin>>p[i].a>>p[i].b>>p[i].c;
    }
    int res=-1e17;
    for( i=-1;i<=1;i+=2){
        for( j=-1;j<=1;j+=2){
            for( k=-1;k<=1;k+=2){
                sort(p+1,p+n+1,cmp);
                int ans1=0,ans2=0,ans3=0;
                for( int s=1;s<=m;s++){
                    ans1+=p[s].a;
                    ans2+=p[s].b;
                    ans3+=p[s].c;
                }
                res= max(res, (ans1*i+ans2*j+ans3*k));
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

 文章来源地址https://www.toymoban.com/news/detail-410344.html

到了这里,关于[ABC100D] Patisserie ABC的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • DELETE Statement

    DELETE 应该是增删改查里最简单的语句了 由于不同类型 db 包括 SQLite3、 MySQL、PostgreSQL 的 DELETE 最简单形态的语法是一样的,本文只以实现最简单的形态为目标,所以,这里只拿 MySQL 举例 MYSQL 的 DELETE 语句也有两种形态: 删除单表的: 额外支持了 ORDER BY 和 LIMIT 删除多表的:只

    2023年04月09日
    浏览(30)
  • PreparedStatement 相比于 Statement的优点

    PreparedStatement 相比于 Statement,有以下几个优点: 1. 预编译:PreparedStatement 对象在执行 SQL 语句之前会进行预编译,这意味着数据库管理系统可以提前解析和编译 SQL 语句,以优化执行计划,从而提高查询性能。 2. 参数化查询:通过使用占位符(?)以及对应的方法(如 setInt、

    2024年02月15日
    浏览(27)
  • Invalid bound statement (not found)

    目录 一、遇到的问题 二、分析思路 1、映射文件 2、测试类 三、解决方案 前几日,有个工作不久的同事找我帮他解决一个 Mybatis 的问题。他写了一个增删改查,但是在启动程序的时候报错:Invalid bound statement (not found) 。他试图解决该异常,花了一个小时还是没有解决,所以

    2024年02月01日
    浏览(43)
  • 执行计划缓存,Prepared Statement性能跃升的秘密

    摘要: 一起看一下GaussDB(for MySQL)是如何对执行计划进行缓存并加速Prepared Statement性能的。 本文分享自华为云社区《执行计划缓存,Prepared Statement性能跃升的秘密》,作者: GaussDB 数据库。 在数据库系统中,SQL(Structured Query Language)语句输入到系统后,一般要经历:词法语法

    2024年02月07日
    浏览(29)
  • nginx设置重定向跳转后ip:[端口]/abc变成ip/abc而报错404

    nginx设置重定向跳转后   ip:[端口]/abc   变成   ip/abc   而报错404 nginx配置: 本地测试项目是否能正常访问: http://192.168.1.22:8088 正常访问 http://192.168.1.22/abc 正常访问 当我需要将192.168.1.22:8088映射到外网ip:[port] 进行外网访问时报错。 假设外网ip=122.23.43.21 路由分配: 122

    2024年02月08日
    浏览(34)
  • JDBC详讲Connection与 jdbc-Statement

     目录 DriverManager:驱动管理对象 功能: Connection:数据库连接对象 功能: 代码实现:  jdbc-Statement  statement作用:  函数介绍: 代码实现:       功能:         (1)注册驱动: 告诉程序该使用那种数据库 代码中常使用:Class.forName(\\\"com.mysql.cj.jdbc.Driver\\\"); 会被加载进内存,

    2024年02月02日
    浏览(23)
  • BindingException:Invalid bound statement (not found)异常

    本文的mybatis是与springboot整合时出现的异常,若使用的不是基于springboot,解决思路也大体一样的。 但在这之前,我们先要知道整合mybatis的三个重要的工作,如此才能排查,且往下看。 我们打开pom文件如下: 这部分代码的作用是指定需要编译到taget目录下的资源文件。我们的

    2024年02月04日
    浏览(29)
  • Invalid bound statement (not found) 原因和解决方法

    在我springboot项目,启动的时候,报了 Invalid bound statement (not found) :绑定语句无效(未找到) mapper接口和mapper.xml文件没有映射起来 1.查看mapper.xml中的namespace和接口mapper文件一致吗 2.看一下 target 里面有没有编译的mapper.xml文件 没有的话,打开maven点击clean一下,重新运行就ok了

    2024年02月14日
    浏览(25)
  • abc343G 题解

    给你 (N) 个由小写字母组成的字符串 (S_1, S_2, ldots, S_N) ,找出一个母串使得它包含所有这些字符串作为它的子串,最小化该母串的长度并输出。 (1 leq N leq 20) , (sum |S_i| leq 2 times 10 ^ 5) (没错洛谷翻译就是我写的) 首先如果有一个字符串被另一个字符串完全包括,那

    2024年03月09日
    浏览(81)
  • rust abc(5): 常量

    学习 rust 语言中常量的使用。 2.1 说明 const 大写名字:数据类型 = 值; 例如定义数学中的 π 为常量, const PI:f64 = 3.1415926; 2.2 运行结果 3.1 不推荐用小写字母作为常量名字 3.2 常量名称中含有小写字母就会报warning 3.3 定义常量时,不指定数据类型会编译报错 抛开变量/常量名字的

    2024年02月11日
    浏览(28)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包