PAT 1037 Magic Coupon
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm> using namespace std; void print(vector<int> &v) {
int len = v.size();
for (int i=; i<len; i++) {
printf(" %d", v[i]);
}
printf("\n");
} int main() {
int NC, NP;
scanf("%d", &NC);
vector<int> C(NC); for (int i=; i<NC; i++) {
scanf("%d", &C[i]);
} scanf("%d", &NP);
vector<int> P(NP);
for (int i=; i<NP; i++) {
scanf("%d", &P[i]);
} sort(C.begin(), C.end(), greater<int>());
sort(P.begin(), P.end(), greater<int>()); int clen = C.size();
int plen = P.size(); int ci = ;
int pi = ;
int dc, dp;
long long sum = ; while (ci < clen && pi < plen && (dc=C[ci]) > && (dp=P[pi]) > ) {
sum += dc * dp;
ci++, pi++;
} ci = clen - ;
pi = plen - ; while (ci >= && pi >= && (dc=C[ci]) < && (dp=P[pi]) < ) {
sum += dc * dp;
ci--, pi--;
}
printf("%lld", sum);
return ;
}
有个case 30+ms是不是方法错了?
PAT 1037 Magic Coupon的更多相关文章
- PAT 1037 Magic Coupon[dp]
1037 Magic Coupon(25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an in ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
- 1037 Magic Coupon (25 分)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an i ...
- PAT 甲级 1037 Magic Coupon
https://pintia.cn/problem-sets/994805342720868352/problems/994805451374313472 The magic shop in Mars ...
- PAT Advanced 1037 Magic Coupon (25) [贪⼼算法]
题目 The magic shop in Mars is ofering some magic coupons. Each coupon has an integer N printed on it, ...
- PAT甲题题解-1037. Magic Coupon (25)-贪心,水
题目说了那么多,就是给你两个序列,分别选取元素进行一对一相乘,求得到的最大乘积. 将两个序列的正和负数分开,排个序,然后分别将正1和正2前面的相乘,负1和负2前面的相乘,累加和即可. #include ...
- PAT (Advanced Level) 1037. Magic Coupon (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 【PAT甲级】1037 Magic Coupon (25 分)
题意: 输入一个正整数N(<=1e5),接下来输入N个整数.再输入一个正整数M(<=1e5),接下来输入M个整数.每次可以从两组数中各取一个,求最大的两个数的乘积的和. AAAAAccep ...
- PTA(Advanced Level)1037.Magic Coupon
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...
随机推荐
- 命令行里打 cd 简直是浪费生命
简评:作为工程师,你在命令行下最常打的命令无非就是 cd 与 ls.这些年你浪费了多少时间? 作为一个程序员或者在 shell 中花费大量时间的人,你可能会经常以一种低效率的方式在目录中来回移动,特别 ...
- Python登陆人人网
#!coding:utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,password): #登 ...
- 16、OpenCV Python 腐蚀和彭胀
__author__ = "WSX" import cv2 as cv import numpy as np def erode_demo(image): print(image. ...
- Python开发MapReduce系列(一)WordCount Demo
原创,转发请注明出处. MapReduce是hadoop这只大象的核心,Hadoop 中,数据处理核心就是 MapReduce 程序设计模型.一个Map/Reduce 作业(job) 通常会把输入的数 ...
- JS 为任意元素添加任意事件的兼容代码
为元素绑定事件(DOM):有两种 addEventListener 和 attachEvent: 相同点: 都可以为元素绑定事件 不同点: 1.方法名不一样 2.参数个数不一样addEventLi ...
- Day 4 上午
内容提要 进制转换 高精度 数论:筛法,gcd/exgcd,逆元 进制转换 10=2^3+2^0=1010(2)10=3^2+3^0=101(3) 10进制x-->k进制:短除法 k进制x--& ...
- elementtaryos root密码更改
在elementtaryos 终端中使用root 账户但不幸忘记密码怎么办?请进行如下操作...... 1.进入高级选项选中recovery mode 2.按e编辑,找到recovery nomode ...
- JAVA之I/O 输入输出流详解
简 介 如何在Java中进行文件的读写,Java IO流是必备的知识.这篇博文主要为您带来Java中的输入输出流的内容,包括文件编码.使用File类对文件和目录进行管理.字节流和字符流的基本操作 ...
- Spring Eureka的使用入门--服务端与客户端
接上篇: Eureka作为注册中心,连接服务端与客户端: 服务端: 依赖包: apply plugin: 'org.springframework.boot' apply plugin: 'io.sp ...
- FTP 两种连接模式
简介 FTP协议要用到两个TCP连接, 一个是命令连接,用来在FTP客户端与服务器之间传递命令:另一个是数据连接,用来上传或下载数据.通常21端口是命令端口,20端口是数据端口.当混入主动/被动模式的 ...