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 ...
随机推荐
- springboot整合mybatis,redis,代码(一)
一 搭建项目,代码工程结构 使用idea或者sts构建springboot项目 二 数据库sql语句 SQLyog Ultimate v12.08 (64 bit) MySQL - 5.7.14-l ...
- RNA-seq分析htseq-count的使用
HTSeq作为一款可以处理高通量数据的python包,由Simon Anders, Paul Theodor Pyl, Wolfgang Huber等人携手推出HTSeq — A Python fra ...
- 洛谷 P4317 花神的数论题(组合数)
题面 luogu 题解 组合数 枚举有多少个\(1\),求出有多少种数 扫描\(n\)的每一位\(1\), 强制选\(0\)然后组合数算一下有多少种方案 Code #include<bits/s ...
- Fliptile (dfs+二进制压缩)
Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He ha ...
- 【AC自动机】【树状数组】【dfs序】洛谷 P2414 [NOI2011]阿狸的打字机 题解
这一题是对AC自动机的充分理解和树dfs序的巧妙运用. 题目背景 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机. 题目描述 打字机上只有28个按键,分别印有26个小写英文字母和' ...
- Codeforces - 570D 离散DFS序 特殊的子树统计 (暴力出奇迹)
题意:给定一棵树,树上每个节点有对应的字符,多次询问在\(u\)子树的深度为\(d\)的所有节点上的字符任意组合能否凑成一个回文串 把dfs序存储在一个二维线性表中,一个维度记录字符另一个维度记录深度 ...
- Dear friends:
To realize the value of ONE YEAR想知道一整年的价值ask the student who has failed a class就去问被当过的学生To realize ...
- [转] JQuery UI Tabs 动态添加页签,并跳转到新页签
[From] https://blog.csdn.net/zhangfeng2124/article/details/76672403 需求: 1.tabs默认只有一个页签,但是需要点击某按钮,动态添 ...
- mysql允许数据库远程连接
2018-11-06 进入数据库 mysql -uroou(用户) -p123456(密码) 授权某个user可远程访问 grant all privileges on *.* to ' with g ...
- javascript 定时任务封装
/** * 定时任务 * 间隔时间,执行次数,要带的参数,要执行的函数. */ var TimingTask = function(time,count,param,fun){ this.id = - ...