• 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 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;
    }
  • 相关阅读:
    Blender文档翻译-Blender库数据的通用属性
    Blender文档翻译-什么是Ghash?
    PythonQt
    QT与Python混合编程经验记录
    WebStorm开发ReactNative过程中导入插件设置智能提示
    原生iOS项目导入ReactNative,各种问题
    关于网易七鱼iOS 端集成
    iOS "_OBJC_CLASS_$_JPUSHService", referenced from: 解决办法
    同时安装使用 两个Xcode切换的一些问题。
    实现一个iOS项目中添加多个target,并制作马甲包。
  • 原文地址:https://www.cnblogs.com/jxust-jiege666/p/6433060.html
Copyright © 2020-2023  润新知