【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

最后的和。
其实可以看成是
∑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的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【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 ...

  3. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 拓扑排序---AOV图

    对一个有向无环图(Directed Acyclic Graph简称DAG)G进行拓扑排序,是将G中全部顶点排成一个线性序列, 使得图中随意一对顶点u和v,若边(u,v)∈E(G),则u在线性序列中出如 ...

  2. ORACLE NOLOGGING研究

    熟悉oracle的人都知道.通过设置oracle的nologging选项,能够使某些操作高速完毕,风险是数据库备份可能失效.能够使用nologging的操作有非常多,搜集资料整理例如以下: 1.索引的 ...

  3. 推送_即时推送_即时通讯_在线Demo

    [伊尚]美容店(万达店)找创业合伙人(限女生) 点击查看Demo 线上预览 运行Demo截图如下: 线上预览

  4. vbs 脚本2

    一些很恶作剧的vbs程序代码 作者: 字体:[增加 减小] 类型:转载 时间:2013-01-16我要评论 恶作剧的vbs代码,这里提供的都是一些死循环或导致系统死机的vbs对机器没坏处,最多关机重启 ...

  5. Linux系统查看当前时间的命令

    转自:https://www.cnblogs.com/redfire/p/7702213.html 一.查看和修改Linux的时区1. 查看当前时区命令 : "date -R"2. ...

  6. jah老师中关于集合的总结

    --------概述:1.Java 集合就像一种容器,可以把多个对象的引用放入容器中 2.Java 集合类可以用于存储数量不等的多个对象,还可用于保存具有映射关系的关联数组3.Java 集合可分为 S ...

  7. 5、Iterator迭代器的使用

    package cn.itcast_02; import java.util.ArrayList; import java.util.Collection; import java.util.Iter ...

  8. python3 常用模块详解

    这里是python3的一些常用模块的用法详解,大家可以在这里找到它们. Python3 循环语句 python中模块sys与os的一些常用方法 Python3字符串 详解 Python3之时间模块详述 ...

  9. (转)使用Vue-Router 2实现路由功能

    注意:vue-router 2只适用于Vue2.x版本,下面我们是基于vue2.0讲的如何使用vue-router 2实现路由功能.推荐使用npm安装. npm install vue-router ...

  10. javascript中模块化知识总结

    JavaScript 模块化开发 1. 模块化介绍 掌握模块化基本概念以及使用模块化带来的好处 当你的网站开发越来越复杂的时候,会经常遇到什么问题? 恼人的命名冲突 繁琐的文件依赖 历史上,JavaS ...