对于这题笔者无解,只有手抄一份正解过来了:

基本思想就是 :

  • 二分答案,对于第x天,计算它最少的花费f(x),<=s就是可行的,这是一个单调的函数,所以可以二分。
  • 对于f(x)的计算,我用了nlog(n)的算法,遍历m个商品,用c[i]乘以前x天里,第t[i]种货币的最便宜的价格,存放到一个数组里,之后排序,计算前k个的和就是f(x)
  • 前x天里,第t[i]种货币的最便宜的价格是通过预处理得到的,很容易的计算一下前缀最小值就行了。

贴代码吧:

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
#define fi first
#define se second
#define mp make_pair
const int maxn = ;
int a[maxn],b[maxn],t[maxn],c[maxn];
int n,m,k,s;
int am[maxn],bm[maxn];
int ida[maxn],idb[maxn];
const int inf = 0x3f3f3f3f; pii pli[maxn];
int id[maxn]; ll f(int x){
ll ret = ;
for (int i=;i<=m;i++){
if (t[i] == ){
pli[i].fi = (ll)c[i] * (ll)am[x]; }
else{
pli[i].fi = (ll)c[i] * (ll)bm[x];
}
pli[i].se = i;
}
sort(pli+,pli+m+);
for (int i=;i<=k;i++){
ret += pli[i].fi;
} return ret;
} int main(){
cin>>n>>m>>k>>s;
am[] = bm[] = inf;
for (int i=;i<=n;i++){
scanf("%d",&a[i]);
if (a[i] < am[i-]){
am[i] = a[i];
ida[i] = i;
}
else{
am[i] = am[i-];
ida[i] = ida[i-];
}
}
for (int i=;i<=n;i++){
scanf("%d",&b[i]);
if (b[i] < bm[i-]){
bm[i] = b[i];
idb[i] = i;
}
else{
bm[i] = bm[i-];
idb[i] = idb[i-];
}
}
for (int i=;i<=m;i++){
scanf("%d%d",&t[i],&c[i]);
} ll low,high,mid;
low = ,high = n;
ll d = -;
while(low <= high){
mid = (low + high) / (ll);
if (f(mid) <= s){
high = mid - ;
d = mid;
for (int i=;i<=k;i++){
id[i] = pli[i].se;
}
}
else{
low = mid + ;
}
}
cout << d <<"\n";
if (d == (ll)-)
return ;
int x = (int)d;
for (int i=;i<=k;i++){
printf("%d %d\n",id[i],t[id[i]]==?ida[x]:idb[x]);
} return ;
}

CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题的更多相关文章

  1. Codeforces Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分,贪心

    D. Gadgets for dollars and pounds 题目连接: http://www.codeforces.com/contest/609/problem/C Description ...

  2. CF# Educational Codeforces Round 3 D. Gadgets for dollars and pounds

    D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...

  3. Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分+前缀

    D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...

  4. Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes

    B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  6. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  7. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  8. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  9. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

随机推荐

  1. Hibernate逍遥游记-第13章 映射实体关联关系-001用外键映射一对一(<many-to-one unique="true">、<one-to-one>)

    1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...

  2. Scanner scanner=new Scanner(System.in)

    import java.util.Scanner;public class inputoutar{   public static void main(String[] args)   throws ...

  3. Jdk命令之jps

    jps -- Java Virtual Machine Process Status Tool jps命令类似于Linux下的ps命令,可以列出本机所有正在运行的java进程.

  4. highcharts 结合phantomjs纯后台生成图片系列二之php2

    上篇文章中介绍了phantomjs的使用场景,方法. 本篇文章详细介绍使用php,highcharts 结合phantomjs纯后台生成图片.包含一步步详细的php代码 一.highcharts 结合 ...

  5. MongoDB 安装和即基本操作

    http://www.mongodb.org/ Agile and Scalable MongoDB (from "humongous") is an open-source do ...

  6. Python3 学习第二弹: 字符串String

    字符串表示问题 常见用法 '' 与 "" 就不提了 一些特殊用法 三引号:接收多行字符串的输入 >>>print('''Oh my God!''') Oh my ...

  7. HDU 4902

    数据太弱,直接让我小暴力一下就过了,一开始没注意到时间是15000MS,队友发现真是太给力了 #include <cstdio> #include <cstring> ],x[ ...

  8. bzoj3140

    首先考虑二维的情况 min(x,y)也就意味着确定最小后,另外一维肯定打满 然后最小那个如果是k的话就相当于用k*1次——这不就是行列覆盖吗,二分图秒之 三维呢?考虑到a*b*c<=5000也就 ...

  9. WebService教程和分析

    1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...

  10. zend studio安装xdebug调试工具

    1. 软件准备 登录xdebug 版本检测地址 http://xdebug.org/wizard.php  :将phpinfo产生的数据页面复制到其文本框内,显示类似如下内容: 二.将下载的xdebu ...