zoukankan      html  css  js  c++  java
  • J. Cola

    J. Cola

    time limit per test

    4.0 s

    memory limit per test

    64 MB

    input

    standard input

    output

    standard output

    At Cola factory there is N bottles on a line. Also, there is a machine that pour cola in these bottles one by one. Every thing was working well. Suddenly, the machine started acting in a strange way !!

    It started choosing a random bottle and pour a random quantity of cola in this bottle.

    When a bottle is full, the rest of the cola goes to the bottle on the right of it, and if it was the last bottle, then the rest of the cola will be wasted .

    As an engineer in this factory, you were given the capacity of every bottle in Litters. Also, you know the record of machine moves because it is stored in the Microcontroller memory of the machine. You are asked to compute the amount of wasted cola, and the amount of cola every bottle has at the end.

    Input

    Your program will be tested on one or more test cases. The first line of the input will be a single integer T the number of test cases. Followed by the test cases.

    Every test case starts with two numbers N and M (1 ≤ N ≤ 105), (1 ≤ M ≤ 105) denoting the number of bottles, and the number of moves the machine had did.

    Then follow N integers on a line separated by spaces. The integer Ci denotes the capacity of the ith bottle (1 ≤ Ci ≤ 109) where (1 ≤ i ≤ N).

    M lines follow denoting the moves. Each line contains two integers X and Y (1 ≤ X ≤ N), (1 ≤ Y ≤ 109) means that the machine poured Yliters of cola in the Xth bottle .

    Output

    For each test case print two lines.

    First line contains the amount of wasted cola.

    The second line contains N integers separated by spaces denoting the amount of cola in every bottle at the end.

    Example
    input
    Copy
    2
    5 3
    5 4 3 2 1
    3 4
    4 4
    1 2
    6 3
    3 4 5 5 6 7
    3 3
    1 8
    5 9
    output
    Copy
    2
    2 0 3 2 1
    0
    3 4 4 0 6 3

    题意:n个杯子,第i个杯子容量为a[i],m次操作,每次往杯子x里倒y单位的水,第i个杯子满了之后多余的水就会倒进第i+1个杯子里,如果第n个杯子也满了那么多余的水就浪费,问浪费了多少水 

    完全按照题目意思模拟肯定是会超时的,所以先不管加可乐的时候会不会漏出,先加进去,加完m次之后,在统一处理大于容量的情况

    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<string>
    #include<vector>
    #include<stack>
    #include<math.h>
    #define mod 998244353
    #define ll long long
    #define MAX 0x3f3f3f3f
    using namespace std;
    struct node 
    {
        ll k;
        ll now;
    }p[100005];
    int main()
    {
        ll n,t,m;
        cin>>t;
        while(t--)
        {
            cin>>n>>m;
            for(ll i=1;i<=n;i++)
            {
                cin>>p[i].k;
                p[i].now=0;
            }
            ll x,y;
            ll ans=0;
            for(ll i=0;i<m;i++)
            {
                cin>>x>>y;
                p[x].now=p[x].now+y;//wa了好多次,有可能多次都是从同一个瓶子开始加可乐
            }
            for(ll i=1;i<n;i++)
            {
                if(p[i].now>p[i].k)
                {
                    p[i+1].now=p[i+1].now+p[i].now-p[i].k;
                    p[i].now=p[i].k;
                }
            }
            if(p[n].now>p[n].k)
            {
                ans=p[n].now-p[n].k;
                p[n].now=p[n].k;
            }
            cout<<ans<<endl;
            for(ll i=1;i<=n;i++)
            {
                if(i!=n)
                    cout<<p[i].now<<' ';
                else
                    cout<<p[i].now<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    RvmTranslator7.4.1-Clipping Box
    使用K-means和高斯混合模型对图像进行聚类
    Python小技巧
    利用SNAP软件进行Sentinel-1A卫星微波影像的预处理
    VScode编译C,头文件显示not found的解决方法
    深浅拷贝
    CSRF攻击:陌生链接不要随便点
    跨站脚本攻击(XSS)
    同源策略:为什么XMLHttpRequest不能跨域请求资源?
    HTTP/2:如何提升网络速度
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11222956.html
Copyright © 2011-2022 走看看