NOIP 2015 推销员

题意:

    有一个喜欢疲劳的推销员,告诉你在一个单口胡同(数轴)中的n户家庭的位置,和向他们推销可以获得的疲劳度。分别输出向(1,2,3,4...n)户人家推销可以得到的最大疲劳值。对了,这个推销员走一格,疲劳度也会加一。

思路:

  贪心,首先按每户人家的推销疲劳度从大到小排序,考虑选定一组,走路带来的疲劳度是定的,就是最远那个*2.

所以对于每个答案= max(sum[ i ]  + mx * 2 , sum [i - 1] + h[i] )。其中sum是排序后对推销疲劳度做的前缀和,而h[i] 保存 从 i 到 n中,最大的(2 * 距离 + 推销疲劳度)。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int ,pii> p3;
//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFFLL; //
const ll nmos = 0x80000000LL; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/ const int maxn = 1e5+;
struct node
{
int s,p;
}a[maxn];
bool cmp(const node &a,const node &b){
return a.p > b.p;
};
int sum[maxn],mx,h[maxn];
int main(){
int n;
scanf("%d", &n);
for(int i=; i<=n; i++)scanf("%d", &a[i].s);
for(int i=; i<=n; i++)scanf("%d", &a[i].p);
sort(a+,a++n,cmp); for(int i=; i<=n; i++){
sum[i] = sum[i-] + a[i].p;
}
for(int i=n; i>=; i--){
h[i] = max(h[i+],a[i].s * + a[i].p);
} for(int i=; i<=n; i++){
if(mx < a[i].s) mx = a[i].s;
int tmp = sum[i] + * mx;
tmp = max(tmp , sum[i-] + h[i]);
printf("%d\n", tmp);
}
return ;
}

LUOGU 2672

最新文章

  1. 腾讯云上免费部署HTTPS
  2. C#多线程环境下调用 HttpWebRequest 并发连接限制
  3. [转]IIS添加MIME扩展类型及常用的MIME类型列表
  4. 在ALV中更新数据库表
  5. hardware control language
  6. iOS - TouchID 指纹识别
  7. iOS图片元数据的读写
  8. Photoshop快捷键
  9. Hibernate一张图
  10. YARN应用程序开发流程(类似于MapReduce On Yarn)本内容版权归(小象学院所有)
  11. 解决:“Ubuntu 10.04 LTS _Lucid Lynx_ - Release i38...
  12. SQL Identity自增列清零方法
  13. 利用PL/SQL Developer工具导出数据到excel,导入excel数据到表
  14. 在webapi中为Action使用dynamic参数实现Post方式调用
  15. Spring学习笔记(二)之装配Bean
  16. oracle 裸设备划分 --centos6.5
  17. Python练手例子(14)
  18. 无法启动此程序,因为计算机中丢失VCRUNTIME140.dll 尝试重新安装此程序以解决此问题
  19. Disconnected from the target VM, address: &#39;127.0.0.1:57178&#39;, transport: &#39;socket&#39;
  20. sql server 性能调优之 资源等待之网络I/O

热门文章

  1. SSD+HDD 安装ubuntu16.04+win7双系统
  2. 思路重要or技术重要?
  3. nginx 之负载均衡 :PHP session 跨多台服务器配置
  4. python的enumerate lambda isinstance filter函数
  5. MemCached的工具类。获取cached中的所有key
  6. 第十章 Fisco Bcos 权限控制下的数据上链实操演练
  7. 【译】尝试使用Nullable Reference Types
  8. [NUnit]No results
  9. Redis——发布和订阅
  10. Spring Boot 2.X 如何快速整合jpa?