【Codeforces Round #519 by Botan Investments E】Train Hard, Win Easy
【链接】 我是链接,点我呀:)
【题意】
【题解】
设每个人做第一题、第二题的分数分别为x,y
我们先假设没有仇视关系。
即每两个人都能进行一次训练。
那么
对于第i个人。
考虑第j个人对它的贡献
如果xi+yjyi+xj的话。
情况类似。
最后对于有仇敌关系的(i,j)的话。
第i个人和第j个人的贡献都减去min(xi+yj,yi+xj)即可。
【代码】
#include <bits/stdc++.h>
#define ll long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;
const int N = 3e5;
struct abc{
int x,y,id;
bool operator < (const abc &b) {
return (x-y)<(b.x-b.y);
}
};
int n,m;
ll ans[N+10];
ll prex[N+10],prey[N+10];
abc a[N+10],b[N+10];
int main(){
#ifdef ccy
freopen("rush.txt","r",stdin);
#endif
scanf("%d%d",&n,&m);
rep1(i,1,n) {
scanf("%d%d",&a[i].x,&a[i].y);
a[i].id = i;
}
rep1(i,1,n) b[i] = a[i];
sort(a+1,a+1+n);
rep1(i,1,n){
prex[i]+=prex[i-1];
prey[i]+=prey[i-1];
prex[i]+=a[i].x;
prey[i]+=a[i].y;
}
//xi+yj<yi+xj
//xi-yi<=xj-yj
//xi+yj>yi+xj
//xi-yi>xj-yj
rep1(i,1,n){
ans[a[i].id] += 1LL*(i-1)*a[i].y+prex[i-1]-prex[0];
ans[a[i].id] += 1LL*(n-i)*a[i].x+prey[n]-prey[i];
}
rep1(i,1,m){
int x,y;
scanf("%d%d",&x,&y);
ans[x]-=min(b[x].x+b[y].y,b[x].y+b[y].x);
ans[y]-=min(b[x].x+b[y].y,b[x].y+b[y].x);
}
rep1(i,1,n){
printf("%lld ",ans[i]);
}
return 0;
}
【Codeforces Round #519 by Botan Investments E】Train Hard, Win Easy的更多相关文章
- 【Codeforces Round #519 by Botan Investments A】 Elections
[链接] 我是链接,点我呀:) [题意] [题解] 枚举k 那么另外一个人的得票就是nk-sum(ai) 找到最小的满足nk-sum(ai)>sum(ai)的k就ok了 [代码] #includ ...
- 【 Codeforces Round #519 by Botan Investments B】Lost Array
[链接] 我是链接,点我呀:) [题意] [题解] 枚举k 不难根据a得到x[0..k-1] 然后再根据a[k+1..n]来验证一下得到的x是否正确就好. [代码] #include <bits ...
- 【Codeforces Round #519 by Botan Investments C】 Smallest Word
[链接] 我是链接,点我呀:) [题意] [题解] 模拟了一两下.. 然后发现. 对于每一个前缀. 组成的新的最小字典序的字符串 要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序 ...
- 【Codeforces Round #519 by Botan Investments D】Mysterious Crime
[链接] 我是链接,点我呀:) [题意] 相当于问你这m个数组的任意长度公共子串的个数 [题解] 枚举第1个数组以i为起点的子串. 假设i..j是以i开头的子串能匹配的最长的长度. (这个j可以给2. ...
- Codeforces Round #519 by Botan Investments
Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #i ...
- Codeforces Round #519 by Botan Investments(前五题题解)
开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...
- Codeforces Round #519 by Botan Investments F. Make It One
https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...
- Codeforces Round #519 by Botan Investments翻车记
A:枚举答案即可.注意答案最大可达201,因为这个wa了一发瞬间爆炸. #include<iostream> #include<cstdio> #include<cmat ...
- 【Codeforces Round #519】
A:https://www.cnblogs.com/myx12345/p/9872082.html B:https://www.cnblogs.com/myx12345/p/9872124.html ...
随机推荐
- 刚開始学习的人非常有用之chm结尾的參考手冊打开后无法正常显示
从网上下载了struts2的參考手冊.chm(本文适用全部已.chm结尾的文件)不能正常打开使用. 如图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/ ...
- 【HNOI 2004】 L语言
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1212 [算法] 字典树 + dp [代码] #include<bits/std ...
- B1047 理想的正方形 RMQ
大家吸取我的教训,想好再写.我码了好长时间,最后发现算法处理的是另一个问题,我处理的是正方形情况的,才能用我优化之后的记忆化搜索,然而矩形就凉了. 先看一下题吧: Description 有一个a*b ...
- 数据结构C++,线性表的实现
#include <iostream>#include <sstream>#include <fstream>#include <cmath>#incl ...
- E20170816-mk
deque 即双端队列.是一种具有队列和栈的性质的数据结构. revert vi. 恢复; 重提; 回到…上; <律>归还; n. 归属; 恢复原来信仰的人; Indicator ...
- 机器人走迷宫(dfs)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590 #include <stdio.h ...
- selenium3 + python - gird分布式(转载)
本篇转自博客:上海-小T 转载链接:https://blog.csdn.net/real_tino/article/details/53467406 Selenium grid是用来分布式执行测试用例 ...
- CSS3 中弹性盒模型--容器的属性
1.display : flex | inline-flex注意,设为 Flex 布局以后,子元素的float.clear和vertical-align属性 将失效. 2.flex-direction ...
- CSS3之 transform和animation区别
CSS3 有3种和动画相关的属性:transform, transition, animation.其中 transform 描述了元素静态样式.而transition 和 animation 却都能 ...
- Gradle sync failed: Could not find method android() for arguments 错误的解决办法
这个问题本质上是Android-gradle的一个使用限制. 对应的英文文档android_tool文档 如果你的App包含了多个Android模块, 应该尽量避免给每个模块手动指定编译SDK版本. ...