【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 ...
随机推荐
- luogu1993 小K的农场
题目大意 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述: 农场a比农场b至少多种植了c个单位的作 ...
- C# Interactive Walkthrough
C# Interactive Walkthrough
- Codeforces--630E--A rectangle(规律)
E - A rectangle Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536KB ...
- LuoguP3621 [APIO2007]风铃
https://zybuluo.com/ysner/note/1140124 题面 题面复杂,戳我 解析 看着这道题... 似乎与[HNOI/AHOI2018]道路有不可言妙的相似之处. (题面吓人, ...
- Spring配置事务中的 transactionAttributes 各属性含义及XML配置
转自:https://blog.csdn.net/z69183787/article/details/17161393 transactionAttributes 属性: PROPAGATION 事务 ...
- angular的directive指令的link方法
比如 指令标签 <mylink myLoad="try()"></mylink> link:function(scope,element,attr){ el ...
- RabbitMQ 官方NET教程(六)【RPC】
在第二个教程中,我们学习了如何使用Work Queues在多个工作者之间分配耗时的任务. 但是如果我们需要在远程计算机上运行功能并等待结果怎么办? 那是一个不同的模式. 此模式通常称为远程过程调用或R ...
- C#方法的练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo ...
- 5.29 @Value{name}无效时怎么办Could not resolve placeholder ‘name22’ in value “${name22}” 错误解决
springboot Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘name22’ in ...
- buf.readInt8函数详解
offset {Number} 0 noAssert {Boolean} 默认:false 返回:{Number} 从该 Buffer 指定的 offset 位置开始读取一个有符号的8位整数值. 设置 ...