#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
int a[*maxn];
int b[*maxn];
int c[*maxn];
int main()
{
int T; scanf("%d",&T);
while(T--)
{
int n,m;
long long num=;
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]),c[i]=a[i]-b[i],num+=c[i];
if(m+num<)
{
printf("-1\n");
}
else
{
long long num=m;
int p1=;
for(int i=;i<=n;i++)
{
num+=c[i];
if(num<)
{ while(num<)
{
num-=c[p1];p1++;
} }
}
printf("%d\n",p1);
} }
}

D.cpp

H 的错误代码

#include<bits/stdc++.h>
using namespace std;
double x[];
double c[];
double d[];
pair<double,int> pa[];
bool up(pair<double,int> px,pair<double,int> py)
{
return px.second<py.second;
}
int main()
{
int T; cin>>T;
while(T--)
{
int n,k; cin>>n>>k;
double r; cin>>r;
for(int i=;i<=k;i++) cin>>x[i];
while(n--)
{
double tot=;
for(int i=;i<=k;i++)
{
cin>>c[i];
d[i]=c[i]-x[i];
pa[i].first=abs(d[i]); pa[i].second=i;
tot+=abs(c[i]-x[i]);
}
tot=tot-r;// cout<<tot<<endl;
sort(pa+,pa++k);
// for(int i=1;i<=k;i++) cout<<pa[i].first<<endl;
int num=k;
int t=;
while(tot>)
{
//cout<<tot/num<<endl;
if(tot/num<=pa[t].first)
{
for(int i=t;i<=k;i++)
{
pa[i].first=pa[i].first-tot/num;
}
break;
}
else
{
double nnn=pa[t].first;
tot=tot-num*nnn;
for(int i=t;i<=k;i++)
{
pa[i].first=pa[i].first-nnn;
}
t++;
num--;
}
}
//for(int i=1;i<=k;i++) cout<<pa[i].first<<"==="<<endl;
sort(pa+,pa++k,up);
//for(int i=1;i<=k;i++) cout<<pa[i].first<<"==="<<endl;
for(int i=;i<=k;i++)
{
//cout<<abs(abs(d[i])-pa[i].first)<<endl;
if(d[i]<) c[i]+=abs(abs(d[i])-pa[i].first);
else c[i]-=abs(abs(d[i])-pa[i].first);
if(i!=) cout<<" ";
cout<<c[i];
}
cout<<endl; }
}
}

ACM-ICPC 2018 北京赛区网络预赛(9.22)的更多相关文章

  1. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  5. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  6. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  7. ACM-ICPC 2018 南京赛区网络预赛B

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  8. ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)

    There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...

  9. ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

随机推荐

  1. 逆袭之旅DAY09.东软实训.接口

    2018年7月5日 package day0705.teacher.test1usb; /** * 测试类 * @author Administrator * */ public class UsbI ...

  2. 微信小程序web-view使用测试总结

    1.后台配置业务域名. 2.在开发者工具的web-view组件中绑定业务域名. 3.点击开发者工具的详情按钮,选择调试基础库高版本,如果不设置,有可能绑定的业务域名内容不显示. 4.如果是公众号上的内 ...

  3. 1-4Controller之Middleware

    1.注册中间件: 新建中间件文件:Activity <?php namespace App\Http\Middleware; use Closure; class Activity{ publi ...

  4. day05_python_1124

    ---恢复内容开始--- 改l1[1:4:2]=[1:32]   对于增加个数 列表按切片取就是列表 ---恢复内容结束--- 01 昨日内容回顾 list: 增: append insert(ind ...

  5. vue-7-表单

    示例: <input v-model="message" placeholder="edit me"> <p>Message is: { ...

  6. VSTO:使用C#开发Excel、Word【1】

    <Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and InfoPath >——By Eric C ...

  7. House Robber III

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  8. sas 选择一段日期,和一定周期,生成日期序列和周期序列

    工作需要,得选择一段日期,和一定周期,生成日期序列和周期序列.暂时用七天为一个周期 data d; format date date9.; do date='04mar2018'd to'05may2 ...

  9. 4.4 C++虚析构函数

    参考:http://www.weixueyuan.net/view/6373.html 总结: 构造函数是不能声明为虚函数的,析构函数可以被声明为虚函数. 将基类的析构函数声明为虚函数之后,派生类的析 ...

  10. MySQL 必知必会学习笔记

    SHOW DATABASES;USE LangLibCEE;SHOW TABLES;SHOW COLUMNS FROM customers;DESC customers; SHOW STATUS WH ...