• 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;
    }
  • 相关阅读:
    [LeetCode] 1268. Search Suggestions System
    [LeetCode] 907. Sum of Subarray Minimums
    [LeetCode] 2034. Stock Price Fluctuation
    [LeetCode] 792. Number of Matching Subsequences
    [LeetCode] 212. Word Search II
    [LeetCode] 828. Count Unique Characters of All Substrings of a Given String
    [LeetCode] 408. Valid Word Abbreviation
    [LeetCode] 1161. Maximum Level Sum of a Binary Tree
    [LeetCode] 1152. Analyze User Website Visit Pattern
    [LeetCode] 636. Exclusive Time of Functions
  • 原文地址:https://www.cnblogs.com/jxust-jiege666/p/6433060.html
Copyright © 2020-2023  润新知