题意:给定两个加血的方式,一个是直接加多少,另一种是加百分之几,然后你能够你选 k 种,问你选哪 k 种。

析:首先肯定要选加的多的,所以我们先排序,从大到小,然后用前缀和存储一下,再去枚举从第一种和从第二种选 i 个,从另一个中选 k-i的,

注意这个 k 可能大于 m+n,讨论一下。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 50000 + 5;
const LL mod = 1e3 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int num, id;
bool operator < (const Node &p) const{
return num > p.num;
}
};
Node a[maxn], b[maxn];
LL sum1[maxn], sum2[maxn]; void print(int n, Node *a){
for(int i = 1; i <= n; ++i)
if(1 == i) printf("%d", a[i].id);
else printf(" %d", a[i].id);
printf("\n");
} int main(){
freopen("buffcraft.in", "r", stdin);
freopen("buffcraft.out", "w", stdout);
int base, k;
while(scanf("%d %d %d %d", &base, &k, &n, &m) == 4){
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i].num);
a[i].id = i;
}
for(int i = 1; i <= m; ++i){
scanf("%d", &b[i].num);
b[i].id = i;
}
if(k >= m + n){
printf("%d %d\n", n, m);
print(n, a);
print(m, b);
continue;
}
sort(a+1, a+n+1);
sort(b+1, b+m+1);
sum1[0] = sum2[0] = 0;
for(int i = 1; i <= n; ++i) sum1[i] = sum1[i-1] + a[i].num;
for(int i = 1; i <= m; ++i) sum2[i] = sum2[i-1] + b[i].num;
LL ans = 0;
int idx = 0;
for(int i = 0; i <= n && i <= k; ++i){
if(m < k - i) continue;
LL tmp = (base + sum1[i]) * (100 + sum2[k-i]);
if(tmp > ans){
ans = tmp;
idx = i;
}
}
for(int i = 0; i <= m && i <= k; ++i){
if(n < k - i) continue;
LL tmp = (base + sum1[k-i]) * (100 + sum2[i]);
if(tmp > ans){
ans = tmp;
idx = -i;
}
} if(idx < 0) idx += k;
printf("%d %d\n", idx, k - idx);
print(idx, a);
print(k - idx, b);
}
return 0;
}

Gym 100531B Buffcraft (贪心+暴力+前缀和)的更多相关文章

  1. Codeforces 990 调和级数路灯贪心暴力 DFS生成树两子树差调水 GCD树连通块暴力

    A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace ...

  2. The 10th Shandong Provincial Collegiate Programming Contest H.Tokens on the Segments(贪心+优先级队列 or 贪心+暴力)

    传送门 •题意 二维平面上有 n 条线段,每条线段坐标为 $(l_i,i),(r_i,i)$: 平面上的每个整点坐标上都可以放置一枚硬币,但是要求任意两枚硬币的横坐标不相同: 问最多有多少条线段可以放 ...

  3. Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理

    A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...

  4. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  5. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  6. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  7. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  8. Codeforces Gym 100637A A. Nano alarm-clocks 前缀和

    A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...

  9. Gym 101775B - Scapegoat - [贪心+优先队列]

    题目链接:http://codeforces.com/gym/101775/problem/B Aori is very careless so she is always making troubl ...

随机推荐

  1. Java有几种线程池?

    Java通过Executors提供四种线程池,分别为:newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程newFixed ...

  2. Python遍历路径下文件并转换成UTF-8编码

    http://www.cnblogs.com/wuyuegb2312/archive/2013/01/11/2856772.html 开始学Python,这篇文章来自于应用需求. os.walk很方便 ...

  3. Java中正则Matcher类的matches()、lookAt()和find()的差别

    參考博文地址:http://www.oseye.net/user/kevin/blog/170 1.matcher():仅仅有在整个字符串全然匹配才返回true,否则返回false. 可是假设部分匹配 ...

  4. HDU 5301 Buildings(2015多校第二场)

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  5. 为什么不建议用Table布局

    Tables的缺点 1.Table要比其它html标记占很多其它的字节.(延迟下载时间.占用server很多其它的流量资源.) 2.Tablle会阻挡浏览器渲染引擎的渲染顺序.(会延迟页面的生成速度, ...

  6. mysql中“Table ‘’ is read only”的解决办法

    之前是在linux下面直接Copy的data下面整个数据库文件夹,在phpMyAdmin里面重新赋予新用户相应权限后,drupal成功连接上数据库.但出现N多行错误提示,都是跟Cache相关的表是‘R ...

  7. vue 配置跨域访问

    主要在config->index.js中配置 proxyTable: { ‘/gameapi’: { changeOrigin: true, // target: ‘http://rap.id. ...

  8. Yii2 mongodb 扩展的where的条件增加大于 小于号

    1. mongodb的where中有比較丰富的 条件.例如以下: static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => ' ...

  9. Python爬虫开发【第1篇】【Scrapy入门】

    Scrapy的安装介绍 Scrapy框架官方网址:http://doc.scrapy.org/en/latest Scrapy中文维护站点:http://scrapy-chs.readthedocs. ...

  10. Android Service 不被杀死并提高优先级

    Android Service 不被杀死有两种思路,一种是将APP设置为系统应用.还有一种是增强service的生命力.即使屏幕背光关闭时也能执行. 因为设置为系统应用须要root.所以一般使用后一种 ...