Contest with Drinks Easy
/*
Problem Statement
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her Ti seconds to solve problem i(1≦i≦N).
Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem Pi will become Xi seconds. It does not affect the time to solve the other problems.
A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
Constraints
- All input values are integers.
- 1≦N≦100
- 1≦Ti≦105
- 1≦M≦100
- 1≦Pi≦N
- 1≦Xi≦105
Input
The input is given from Standard Input in the following format:
N
T1 T2 … TN
M
P1 X1
P2 X2
:
PM XM
Output
For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.
Sample Input 1
3
2 1 4
2
1 1
2 3
Sample Output 1
6
9
If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.
If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.
Sample Input 2
5
7 2 3 8 5
3
4 2
1 7
4 13
Sample Output 2
19
25
30 */ #include <iostream> using namespace std;
#define h 100100 int t[h]; int main()
{
int n;
cin >> n;
int i = 1;
while(n --)
{
cin >> t[i];
i ++;
}
int m;
cin >> m;
while(m --)
{
int p, x;
cin >> p >> x;
int c;
c = t[p];
t[p] = x;
int sum = 0;
for(int j = 1; j < i; j ++)
{
sum += t[j];
}
cout << sum <<endl;
t[p] = c;
}
return 0;
}
Contest with Drinks Easy的更多相关文章
- [arc066f]Contest with Drinks Hard
题目大意: 有一些物品,每个买了有代价. 如果存在一个极大区间[l,r]内的物品都被买了,这个区间长度为k,可以获得的收益是k*(k+1)/2. 现在若干次询问,每次问假如修改了某个物品的价格,最大收 ...
- AtCoder Regular Contest 066 F Contest with Drinks Hard
题意: 你现在有n个题目可以做,第i个题目需要的时间为t[i],你要选择其中的若干题目去做.不妨令choose[i]表示第i个题目做不做.定义cost=∑(i<=n)∑(i<=j<= ...
- 【ARC066】F - Contest with Drinks Hard
题解 我写的斜率维护,放弃了我最擅长的叉积维护,然后发现叉积维护也不会爆long long哦-- 一写斜率维护我的代码就会莫名变长而且难写--行吧 我们看这题 推了推式子,发现这是个斜率的式子,但是斜 ...
- Arc066_F Contest with Drinks Hard
传送门 题目大意 有一个长为$N$的序列$A$,你要构造一个长为$N$的$01$序列使得$01$序列全部由$1$组成的子串个数$-$两个序列的对应位置两两乘积之和最大,每次独立的询问给定$pos,x$ ...
- AtCoder Grand Contest 005F - Many Easy Problems
$n \leq 200000$的树,从树上选$k$个点的一个方案会对$Ans_k$产生大小为“最小的包括这$k$个点的连通块大小”的贡献.求每个$Ans_k$.膜924844033. 看每个点对$An ...
- @atcoder - ARC066F@ Contest with Drinks Hard
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定序列 T1, T2, ... TN,你可以从中选择一些 Ti ...
- [atARC066F]Contest with Drinks Hard
先不考虑修改,那么很明显即对于每一个极长的的区间,若其长度为$l$,有${l+1\choose 2}$的贡献 考虑dp去做,即$f_{i}$表示前$i$个数最大的答案,则$$f_{i}=\max(\m ...
- AT2274 [ARC066D] Contest with Drinks Hard
先考虑不修改怎么做,可以令 \(dp_i\) 表示前 \(i\) 个题能获得的最大得分.那么我们有转移: \[dp_i = \min\{dp_{i - 1}, dp_{j} + \frac{(i - ...
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
随机推荐
- mysql 去除字符串中前后空格
update table set field = replace(replace(replace(field,char(9),''),char(10),''),char(13),'');
- C# 保证数据长度相同
/// <summary> /// 保证数据长度相同 /// </summary> /// <param name="obj"></par ...
- js高级-原型链
JavaScript是基于原型的面向对象的语言(相当于一个基类,父类),而不是像Java通过类模板构造实例,通过原型实现属性函数的复用 函数都有 prototype属性 指向函数的原型对象 只有函数根 ...
- node中可读流、可写流
javascript的一个不足之处是不能处理二进制数据,于是node中引入了Buffer类型.这个类型以一个字节(即8位)为单位,给数据分配存储空间.它的使用类似于Array,但是与Array又有不同 ...
- 对于“2017面向对象程序设计(Java)第就十周学习总结”存在问题的反馈
1.“学生们普遍反映对泛型相关知识点的理解有一些难度,而且对泛型有关程序的编写有些困难.希望老师再次讲解.同学们普遍反映第四.第五个实验较难,大部分同学不能独立完成实验,希望老师能在课堂上详细解答.根 ...
- 给tbody加垂直滚动条的具体思路
[给tbody加垂直滚动条的具体思路] 给tbody加垂直滚动条的思路就是把tbody设置成display:block,然后就对其高度设置一个固定值,overflow设置成auto即可 参考:http ...
- Bootstrap的aria-label和aria-labelledby
[Bootstrap的aria-label和aria-labelledby] 用于盲人阅读的属性,基本也没什么用. 参考:http://blog.csdn.net/liuyan19891230/art ...
- 字符串相似度算法(编辑距离Levenshtein Distance)的应用场景
应用场景 DNA分析: 将DNA的一级序列如β-球蛋白基因的第一个外显子(Exon)转化为分子“结构图”,然后由所得“结构图”提取图的不变量,如分子连接性指数.以图的不变量作为自变量,再由相似度计算公 ...
- 基于xtrabackup GDIT方式不锁库作主从同步(主主同步同理,反向及可)
1.安装数据同步工具 注:xtrabackup 在数据恢复的时候比mysqldump要快很多,特别是大数据库的时候,但网络传输的内容要多,压缩需要占用时间. yum install https://w ...
- poj3292(筛法+打表)
题目链接:https://vjudge.net/problem/POJ-3292 题意:定义4n+1数(简称H数),H数分为三类:unit,即为1; H-primes,只能分解为1×自身,类似于我们平 ...