My Friend of Misery Gym - 101086A——思维题

原题链接:https://codeforces.com/gym/101086/problem/A

With the SCPC2015 getting closer, Noura Boubou, SCPC Head of Media, was very busy to the extent of not having time to recharge her phone's credit balance. However, her best friend, Nicole, was kind enough to transfer her own credit for the sake of keeping Noura online 24/7.

The phone credit transfer system in Syria works in the following way: Each successful transfer operation withdraws 25 extra credit units from the sender's balance, but it doesn't cost anything when a transfer operation is unsuccessful due to non sufficient credit balance.

Given the log of credit transfer requests and the response from the system to each request, in the form: Amount of transfer, and result of operation (either successful or unsuccessful), can you find out the number of possible initial credit balance values that Nicole could have had which satisfy the given log file?

Note that the initial credit balance is always a non negative integer.

Input

The first line of input contains an integer T (1 ≤ T ≤ 256), the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 105), the number of operations in the log of credit transfer requests.

Each of the following N lines contains an integer mi (1 ≤ mi ≤ 106), the amount of credit to transfer, followed by .

  • { + } denotes a successful operation.
  • { - } denotes an unsuccessful operation.

Each log contains at least one unsuccessful operation.

Output

For each test case, print a single line that contains the number of possible initial credit balance values that Nicole could have had.

题意:

要求出的是sender可以拥有的流量费的所有种可能。

注意:

第一次出现  -   的时候,他当时所可以拥有的流量费的最大值一定是他拥有流量费的上界,所以第一次出现  -  的时候特判一下。

AC代码:

#include
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
const ll N = 1e5+10;

int main()
{
     int T;
     cin>>T;
     while(T--)
     {
          int n;
          cin>>n;
          int sum = 0;
          int pl = 0;
          int i=1;
          for(i=1; i<=n; i++)
          {
               int x;
               char c;
               cin>>x>>c;
               if(c=='+')
               {
                    sum = sum + x + 25;
               }
               else
               {
                    pl = sum + x + 24;
                    i++;
                    break;
               }
          }
          for(;i<=n; i++)
          {
               int x;
               char c;
               cin>>x>>c;
               if(c=='+')
               {
                    sum = sum + x + 25;
               }
               else
               {
                    if(sum+x+25<=pl)
                         pl = sum + x + 24;
               }
          }

          cout<

 

你可能感兴趣的:(ACM-ICPC,C++)