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

【题意】

在这里输入题意

【题解】

最后的和。
其实可以看成是
∑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. [Javascript Crocks] Recover from a Nothing with the `alt` method

    Once we’re using Maybes throughout our code, it stands to reason that at some point we’ll get a Mayb ...

  2. [React] Refactor componentWillReceiveProps() to getDerivedStateFromProps() in React 16.3

    The componentWillReceiveProps() method is being deprecated in future version of React (17). Many of ...

  3. 改你MB需求!

    改你MB需求! 原创 2015-12-08 尖峰视界 尖峰视界 我敏锐的觉察到,产品经理的头像開始闪动了.在0.1秒的时间内,我全身的血液都冲向了大脑.果然.右上角弹出了文件传输窗体. "最 ...

  4. 消除ADB错误“more than one device and emulator”的方法

    当我连着手机充电的时候,启动模拟器调试,运行ADB指令时,报错. C:\Users\gaojs>adb shell error: more than one device and emulato ...

  5. luogu3093 牛奶调度

    题目大意 有一些奶牛,它们能挤出不同数量的奶,要想挤它要在其所对应的最后期限前完成.一个时间点只能挤完一个奶牛.问最多能挤出多少奶? 题解 如果我们要挤一个奶牛,我们要让他越晚被挤越好,这样构成最优解 ...

  6. poj 3913(水)

    Description You have devised a new encryption technique which encodes a message by inserting between ...

  7. C# Log4Net简单使用方法

    log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具. 使用log4net,一个很明显的好处 ...

  8. Linux Shell Scripting Cookbook 读书笔记 4

    正则, grep 1. 正则表达式  正则表达式  描述  示例 ^ 行起始标记  ^hell匹配以hell开头的行 $ 行尾标记  test$匹配以test结尾的行 . 匹配任意一个字符  hell ...

  9. python 模块导入详解

    本文不讨论 Python 的导入机制(底层实现细节),仅讨论模块与包,以及导入语句相关的概念.通常,导入模块都是使用如下语句: import ... import ... as ... from .. ...

  10. Spring学习笔记之依赖的注解(2)

    Spring学习笔记之依赖的注解(2) 1.0 注解,不能单独存在,是Java中的一种类型 1.1 写注解 1.2 注解反射 2.0 spring的注解 spring的 @Controller@Com ...