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 ...
随机推荐
- Hibernate的工作流程以及三种状态
Hibernate的工作流程: 1. 读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3. 打开Sesssion 4.创建事务Transation 5. 持久化操作 6. ...
- Python3之pickle模块
用于序列化的两个模块 json:用于字符串和Python数据类型间进行转换 pickle: 用于python特有的类型和python的数据类型间进行转换 json提供四个功能:dumps,dump,l ...
- 29.最小的K个数
题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 思路分析: 利用快速排序的partition函数,par ...
- centos 安装搜狗
原文:https://www.cnblogs.com/blueherb/p/9521827.html 1.通过centos的搜狐到百度下载linux fo sougou 注:找到下载路径(定义为A) ...
- ionic4 添加自定义字体图标
在angular.json中的style中引入css文件: 然后在variables.scss中添加内容:
- 浏览器端 禁止 html 使用后退 或者替换后退功能..
知乎大佬的代码: 作者:独夜行 链接:https://www.zhihu.com/question/40511430/answer/166467343 来源:知乎 著作权归作者所有.商业转载请联系作者 ...
- HDU - 4825 01字典树套路题
/*H E A D*/ struct Trie{ int son[maxn<<2][2]; int b[67],tot; void init(){ // memset(son,0,size ...
- [转] 【译】让人倾倒的 11 个 npm trick
[From] https://segmentfault.com/a/1190000006804410 本文转载自:众成翻译译者:文蔺链接:http://www.zcfy.cc/article/1206 ...
- Spring 配置 Apache Commons Logging
第一次用spring framework,刚配了个最简单的项目,启动出现如下错误,查了知道原来spring要依赖Apache common logging包.只需要添加到项目library中即可.可从 ...
- 剑指offer5.1——O(n)的复杂度合并两个有序数组
#include"iostream" #include"stdio.h" using namespace std; int* ArrayMerge(int *a ...