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

【题意】

在这里输入题意

【题解】

最后的和。
其实可以看成是
∑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] IntersectionObserver -- Lazy Load Images on a Website

    When it comes to websites performance is king. How long it takes for a page to load can mean the dif ...

  2. 寻找不到iframe元素

    一直找不到元素,是因为有两层iframe的 找iFrame元素方法如下 1.iFrame有ID 或者 name的情况//进入id="frame1"的frame中,定位id=&quo ...

  3. SQL SERVER读书笔记:执行计划

    执行计划对性能影响甚大. 系统是怎么得出一个号的执行计划的?主要是依赖于准确的统计信息.统计信息准确的前提下,执行语句重用性高,可避免频繁编译,这也有助于提高性能. 但如果怀疑统计信息不够准确,可以强 ...

  4. oc23--变量修饰符

    // // Person.h #import <Foundation/Foundation.h> /* @public:所有类访问 @private:本类访问 @protected:本类子 ...

  5. 安装visual studio 2013--【转】

    本文转载自:http://blog.csdn.net/tina_ttl/article/details/51544733#1下载-visual-studio-ultimate-2013安装包 1.下载 ...

  6. 【POJ 3071】 Football

    [题目链接] http://poj.org/problem?id=3071 [算法] 概率DP f[i][j]表示第j支队伍进入第i轮的概率,转移比较显然 [代码] #include <algo ...

  7. Juniper路由器

    Juniper路由器入门之一:需要子接口的端口配置 set interfaces fe-2/0/1 vlan-tagging              ――――在配置接口启用封装VLAN set in ...

  8. php如何将网上的图片下载到本地

    <?phpheader("Content-Type: application/force-download");header("Content-Dispositio ...

  9. 时间&物质&效率

    由于我的家庭是地道的农民家庭,在上学的时候,父母很辛苦的供我读初中,高中,大学. 现在我想说的是,用时间来换取效率是我求学时最大的遗憾. 举一个例子吧:每次回家坐火车,火车很费时间,假如我不缺钱,完全 ...

  10. The AJAX response: XML, HTML, or JSON?

    shared from: http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html 1. 返回XML文档 对返回的XML ...