Round #169 (Div. 2)C. Little Girl and Maximum Sum

1、用退化的线段树(也就是没有区间查询)做。。。

2、注意longlong。

#include<cstdio>
#include<cstring>

#include<iostream>
#include<algorithm>
using namespace
std;
int n,q;
int a[200010],s[200010];
int main(){
   
scanf("%d%d",&n,&q);
for(int
i=1;i<=n;i++)

scanf("%d",&a[i]);
sort(a+1,a+1+n);
memset(s,0,sizeof(s));
   
for(int j=1;j<=q;j++){
int l,r;
scanf("%d%d",&l,&r);
s[l]++;
s[r+1]--;
}
for(int i=1;i<n;i++)
s[i+1]+=s[i];
sort(s+1,s+1+n);
long
long ans=0;
for(int
i=1;i<=n;i++)
ans+=(long
long)a[i]*s[i];

cout<<ans<<endl;
return 0;
}

Round #169 (Div. 2)C. Little Girl and Maximum Sum,布布扣,bubuko.com

时间: 2024-10-22 10:32:25

Round #169 (Div. 2)C. Little Girl and Maximum Sum的相关文章

Codeforces Round #169 (Div. 2)C. Little Girl and Maximum Sum

传送门 Description The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries,

Codeforces Round #169 (Div. 2)---C. Little Girl and Maximum Sum(简单贪心)

The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defi

Codeforces Round #259 (Div. 1)——Little Pony and Expected Maximum

题目连接 题意: 输入n.m,表示一个n面的色子(面上的值为1-n),投掷m次,求得到的最大值的期望(1?≤?m,?n?≤?105). 分析: 假设当前得到的最大值是Max,那么对应的概率是:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ),(1 <= k <= n):化简就可以得到:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ) - ((Max - 1

codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j-1],求f[n][n].C++代码: #include <iostream> using namespace std; int n, f[11][11]; int main() { cin >> n; for (int i=1;i<=n;i++) f[i][1] = f[1][

BestCoder Round #11 (Div. 2) 前三题题解

题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 216    Accepted Submission(s): 166 Problem De

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

BestCoder Round #11 (Div. 2)题解集合

Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 155    Accepted Submission(s): 110 Problem Description Bob and Alice got separated in the Square, they agreed that if they get sepa

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo