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

【题意】

【题解】

设每个人做第一题、第二题的分数分别为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的更多相关文章

  1. 【Codeforces Round #519 by Botan Investments A】 Elections

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 那么另外一个人的得票就是nk-sum(ai) 找到最小的满足nk-sum(ai)>sum(ai)的k就ok了 [代码] #includ ...

  2. 【 Codeforces Round #519 by Botan Investments B】Lost Array

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 不难根据a得到x[0..k-1] 然后再根据a[k+1..n]来验证一下得到的x是否正确就好. [代码] #include <bits ...

  3. 【Codeforces Round #519 by Botan Investments C】 Smallest Word

    [链接] 我是链接,点我呀:) [题意] [题解] 模拟了一两下.. 然后发现. 对于每一个前缀. 组成的新的最小字典序的字符串 要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序 ...

  4. 【Codeforces Round #519 by Botan Investments D】Mysterious Crime

    [链接] 我是链接,点我呀:) [题意] 相当于问你这m个数组的任意长度公共子串的个数 [题解] 枚举第1个数组以i为起点的子串. 假设i..j是以i开头的子串能匹配的最长的长度. (这个j可以给2. ...

  5. Codeforces Round #519 by Botan Investments

    Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #i ...

  6. Codeforces Round #519 by Botan Investments(前五题题解)

    开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...

  7. Codeforces Round #519 by Botan Investments F. Make It One

    https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...

  8. Codeforces Round #519 by Botan Investments翻车记

    A:枚举答案即可.注意答案最大可达201,因为这个wa了一发瞬间爆炸. #include<iostream> #include<cstdio> #include<cmat ...

  9. 【Codeforces Round #519】

    A:https://www.cnblogs.com/myx12345/p/9872082.html B:https://www.cnblogs.com/myx12345/p/9872124.html ...

随机推荐

  1. @SpringBootApplication注解

    @SpringBootApplication注解表明了SpringBoot的核心功能,即自动配置. @SpringBootApplication(主配置类): @SpringBootConfigura ...

  2. multiple web application host under the same website on IIS (authentication mode)

    第一种方式,修改forms的name how to set the forms authentication cookie path assume you have already solved th ...

  3. java-com-util-common-service:BaseService.java

    ylbtech-java-com-util-common-service:BaseService.java 1.返回顶部 1. package com.shineyoo.manager.util.co ...

  4. 判断文件是否为空 C++

    #include <sys/stat.h> int stat(const char *restrict pathname, struct stat *restrict buf); stru ...

  5. 5.27 indeed 第三次网测

    1. 第一题, 没有看 2. 暴力枚举.每一个部分全排列, 然后求出最大的请求数. #include<bits/stdc++.h> #define pb push_back typedef ...

  6. LeetCode Weekly Contest 28

    1. 551. Student Attendance Record I 2. 552. Student Attendance Record II hihocode原题,https://hihocode ...

  7. Laravel5.1学习笔记5 请求

    HTTP 请求 #取得请求实例 #基本的请求信息 #PSR-7 请求 #取出输入数据 #旧的输入 #Cookies #文件 #取得请求实例(此部分文档5.1完全重写,注意) 要通过依赖注入获取当前HT ...

  8. YOLO训练Pedestrain

    Pedestrain dl  使用darknet训练: 1. Inria 创建 yolo-inria.cfg 从cfg/yolo-voc.2.0.cfg拷贝一份,修改batch=64, subdivi ...

  9. Electron结合React开发环境遇到的问题

    链接 将create-react-app与electron集成在了一个项目中.但是在React中无法使用electron 当在React中使用require('electron')时就会报TypeEr ...

  10. Visual Studio Code 插件推荐

    Path Intellisense - 路径补全 HTML Snippets - HTML 标记增强 Markdown+Math - Markdown 增强(数学表达式) vscode-icons - ...