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

【题意】

在这里输入题意

【题解】

最后的和。
其实可以看成是
∑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. HDU 5355 Cake

    HDU 5355 Cake 更新后的代码: 今天又一次做这道题的时候想了非常多种思路 最后最终想出了自觉得完美的思路,结果却超时 真的是感觉自己没救了 最后加了记忆化搜索,AC了 好了先说下思路吧.不 ...

  2. iOS 加入粘贴板的功能(复制功能)

    1.   UIPasteboard *board = [UIPasteboard generalPasteboard]; board.string = @" 须要粘贴的问题字符串" ...

  3. HTML5和CSS3中的交互新特性

    当文章的标题是一副用photoshop制作的图片,那么势必在搜索引擎中无法搜索到.并且因为图片的体积不算小.可能在网速慢的的时候不得不耐心的等待图片的刷新. 所以.我们来谈谈有没有一种新的方法能够避免 ...

  4. 【cocos2d-x 3.7 飞机大战】 决战南海I (十二) 游戏结束场景

    游戏结束的时候,要显示分数.还要可以选择是返回主场景还是退出游戏 // 退出游戏 void menuCloseCallback(cocos2d::Ref* pSender); // 返回主界面 voi ...

  5. ASIHTTPRequest框架的简单使用

    ASIHttpRequest是一款及其强劲的HTTP訪问开源项目.让简单的API完毕复杂的功能,如:异步请求,队列请求,GZIP压缩.缓存,断点续传,进度跟踪,上传文件.HTTP认证.在新版本号中,还 ...

  6. [Javascript] 轻量级的JavaScript日期处理类库xDate使用指南

    XDate是一个请谅解的JavaScript的原生Date对象的封装库,提供增强的功能解析,格式化和日期处理.使用起来就和JavaScript自己的对象和方法一样,非常简单. XDate是一个请谅解的 ...

  7. IP与以太网的包收发操作

    你好,这是<网络是怎样连接的>的第3篇读书笔记,第二章<用电信号传输TCP/IP>后半部分:IP与以太网的包收发操作. 先看下经典的TCP/IP四层模型: 通常,下层模块支撑上 ...

  8. .Net Core Autofac实现依赖注入

    Autofac 是一款适用于Microsoft .NET 4.5, Silverlight 5, Windows Store apps, and Windows Phone 8 apps的超赞的 Io ...

  9. Windows显示我的电脑到桌面以及给一些程序设置快捷键

    Windows显示我的电脑到桌面,我测试的是windows server 2012和windows10  1.按Win(键盘上的微软徽标键)+R,输入: rundll32.exe shell32.dl ...

  10. 记我安装Caffe的血泪史(1)

    Caffe的安装我主要参考的是这篇博客 http://blog.csdn.net/ubunfans/article/details/47724341 按照他的方法我很快就安好了cuda8(为后面安装了 ...