【Codeforces 276C】Little Girl and Maximum Sum
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
最后的和。
其实可以看成是
∑bi*ai 的形式。
这里的bi这个系数表示的是有多少个区间覆盖了ai这个元素。
既然这样的话。
那么我们可以用个技巧li++,ri--的技巧算出来每个bi.(或者用线段树的成段更新应该也可以
然后把bi从大到小排个序
然后把ai也从大到小排个序。
(这样就能满足ai大的,他的系数也比较大了。
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n,q,a[N+10],b[N+10];
int in[N+10],out[N+10];
int main()
{
#ifdef LOCAL_DEFINE
freopen("rush.txt","r",stdin);
#endif // LOCAL_DEFINE
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> q;
for (int i = 1;i <= n;i++) cin >> a[i];
while (q--){
int l,r;
cin >> l >> r;
in[l]++;out[r+1]++;
}
int cur = 0;
for (int i = 1;i <= n;i++){
cur+=in[i];cur-=out[i];
b[i] = cur;
}
sort(a+1,a+1+n);
sort(b+1,b+1+n);
long long ans = 0;
for (int i = 1;i <= n;i++)
ans = ans + 1LL*a[i]*b[i];
cout<<ans<<endl;
return 0;
}
【Codeforces 276C】Little Girl and Maximum Sum的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 509A】Maximum in Table
[题目链接]:http://codeforces.com/contest/509/problem/A [题意] 给你一个递推式f[i][j] = f[i-1][j]+f[i][j-1]; 让你求f[i ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【81.82%】【codeforces 740B】Alyona and flowers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【35.29%】【codeforces 557C】Arthur and Table
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Composer 很重要很重要 内核 原理
话题先攒着,过来再来写 先来一张原理图 composer的原理和其他的包管理工具都是一样的,只是实现的细节有些不同,例如yum,例如brew,例如apt-get还有packets. 使用自己的comp ...
- 文字录入无限制Undo,Redo的实现
这里只针对Edit的内容做一个简单的undo,redo功能: 原理就是,将新增字符和相关信息添加到undo列表,在undo动作时,取记录信息,并在edit中删除新增的字符,然后将此动作添加到redo列 ...
- win10查看系统启动项,并且禁用
打开任务管理器,有一个叫做start up的选项卡,里面的东西就是启动项. 右键选中需要disable的,然后禁用.
- Swift - 将Data数据转换为[UInt8](bytes字节数组)
有时上传或者发送图片.文字时,需要将数据转换为 bytes 字节数组.下面介绍两种将 Data 转换为 [UInt8] 的方法. 假设我们有如下 Data 数据要转换: 1 let data = &q ...
- hdoj--5620--KK's Steel(斐波那契数)
KK's Steel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- MongoDB如何实现读写分离
MongoDB如何实现读写分离 MongoDB复制集(Replica Set)通过存储多份数据副本来保证数据的高可靠,通过自动的主备切换机制来保证服务的高可用.但需要注意的时,连接副本集的姿势如果不对 ...
- 软件-集成开发环境:IDE
ylbtech-软件-集成开发环境:IDE 集成开发环境(IDE,Integrated Development Environment )是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器. ...
- 在Spring Boot中使用Spring-data-jpa实现分页查询
转自:https://www.cnblogs.com/sandea/p/8275890.html 在我们平时的工作中,查询列表在我们的系统中基本随处可见,那么我们如何使用jpa进行多条件查询以及查询列 ...
- N数码问题的启发式搜索算法--A*算法python实现
一.启发式搜索:A算法 1)评价函数的一般形式 : f(n) = g(n) + h(n) g(n):从S0到Sn的实际代价(搜索的横向因子) h(n):从N到目标节点的估计代价,称为启发函数(搜索的纵 ...
- [Plugin] WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
URL:http://www.cnblogs.com/chillsrc/archive/2010/02/21/1670594.html 说明:功能完全支持ie和firefox浏览器! 一般的WEB方式 ...