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 ...
随机推荐
- ulimit -n 查看可以打开的最大文件描述符的数量
具体ulimit命令参考 https://www.cnblogs.com/wangkangluo1/archive/2012/06/06/2537677.html
- 了解一个名词——GTD
概念:就是Getting Things Done的缩写,翻译过来就是“把事情做完”,是一个管理时间的方法. 核心理念概括:就是必须记录下来要做的事,然后整理安排并使自己一一去执行. 五个核心原则是:收 ...
- SDUT OJ 效率至上(线段树)
效率至上 Time Limit: 5000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 题意很简单,给出一个数目为n ...
- 条目十四《使用reserve来避免不必要的重新分配》
条目十四<使用reserve来避免不必要的重新分配> 使用vector和string的插入元素的时候,我们是不用担心内存问题的(只要不超过容器的max_size).因为底层有分配子管理内存 ...
- [POI2007]ZAP-Queries 数学
题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...
- Spring Eureka的使用入门
Eureka调度服务: Gradle依赖包: 基础框架依赖配置核心代码: buildscript { repositories { mavenCentral() } dependencies {cla ...
- mysql 查询库中有几张表
SELECT COUNT(*) TABLES, table_schemaFROM information_schema.TABLESWHERE table_schema = '999*999' 999 ...
- php 实现无限极分类
原始数据 $array = array( array('id' => 1, 'pid' => 0, 'n' => '河北省'), array('id' => 2, 'pid' ...
- 洛谷 P3616 富金森林公园题解(树状数组)
P3616 富金森林公园 题目描述 博艾的富金森林公园里有一个长长的富金山脉,山脉是由一块块巨石并列构成的,编号从1到N.每一个巨石有一个海拔高度.而这个山脉又在一个盆地中,盆地里可能会积水,积水也有 ...
- java的长字符串转化为短字符串
public class CustomEncrypt{ public static void main( String[] args ) { /* * c#给的正确测试用例: id=>mid * ...