Submission #3377174


Source Code Expand

#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;

using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
    freopen("water.in","r",stdin);
    freopen("water.out","w",stdout);
#endif
}

const int MAXN=1e6+7;

static int n;

static int a[MAXN],b[MAXN];

inline void init()
{
	read(n);
	Rep(i,1,n)read(a[i]),read(b[i]);
}

static ll cnt;

inline void solve()
{
	Repe(i,n,1)if((a[i]+cnt)%b[i])cnt+=b[i]-(a[i]+cnt)%b[i];
	printf("%lld\n",cnt);
}

int main()
{
    init();
    solve();
    return 0;
}

Submission Info

Submission Time
Task A - Multiple Array
User Great_Influence
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1676 Byte
Status AC
Exec Time 7 ms
Memory 4736 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 18
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 7 ms 4736 KB
02.txt AC 7 ms 4736 KB
03.txt AC 7 ms 4736 KB
04.txt AC 7 ms 4736 KB
05.txt AC 7 ms 4736 KB
06.txt AC 7 ms 4736 KB
07.txt AC 5 ms 4736 KB
08.txt AC 7 ms 4736 KB
09.txt AC 6 ms 4736 KB
10.txt AC 7 ms 4736 KB
11.txt AC 5 ms 4736 KB
12.txt AC 4 ms 4736 KB
13.txt AC 6 ms 4736 KB
14.txt AC 7 ms 4736 KB
15.txt AC 1 ms 2304 KB
16.txt AC 1 ms 2304 KB
s1.txt AC 1 ms 2304 KB
s2.txt AC 2 ms 2304 KB