Submission #2404782


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int n;
vector<int> a, b, neces;
LL ans = 0;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    a.assign(n, 0);
    b.assign(n, 0);
    neces.assign(n, 0);

    REP(i, n) cin >> a[i] >> b[i];
    
    for(int i = n-1; i >= 0; i--){
        neces[i] = ((ans + a[i]) % b[i] == 0 ? 0 : b[i] - (ans + a[i]) % b[i]);
        ans += neces[i];
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task A - Multiple Array
User wheson
Language C++14 (GCC 5.4.1)
Score 300
Code Size 992 Byte
Status AC
Exec Time 26 ms
Memory 1408 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 23 ms 1408 KB
02.txt AC 22 ms 1408 KB
03.txt AC 23 ms 1408 KB
04.txt AC 23 ms 1408 KB
05.txt AC 23 ms 1408 KB
06.txt AC 23 ms 1408 KB
07.txt AC 18 ms 1408 KB
08.txt AC 23 ms 1408 KB
09.txt AC 19 ms 1408 KB
10.txt AC 23 ms 1408 KB
11.txt AC 18 ms 1408 KB
12.txt AC 14 ms 1408 KB
13.txt AC 18 ms 1408 KB
14.txt AC 26 ms 1408 KB
15.txt AC 1 ms 256 KB
16.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB