G - 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≦iN).

Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦iM), 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≦PiN
  • 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 11and 4 seconds, respectively, totaling 6 seconds.

If Joisino takes drink 2, the time it takes her to solve each problem will be 23and 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<cstdio>
int main()
{
	int n,t[100005],m,p,x,sum,sum2;
	while(scanf("%d",&n)!=EOF)
	{
		sum=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&t[i]);
			sum=sum+t[i];
		}
		scanf("%d",&m);
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&p);
			scanf("%d",&x);
			sum2=sum+x-t[p];
			printf("%d\n",sum2);
		}
		    
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值