Submission #1073875


Source Code Expand

#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
using namespace std;

// JAI SHREE KRISHNA

// 1.25H Dude!!! 1.25 H

//!!!C***

//Remember the Past,Play the Future

vector<pii>v1;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    v1.clear();
    ll n;
    cin>>n;
   loop(i,n)
    {
        ll a,b;
        cin>>a>>b;
        v1.push_back({a,b});
    }
    ll ans  =0  ;
    ll curr = 0 ;
    for(ll j = v1.size()-1;j>=0;j-=1)
    {
        v1[j].first+=curr;
        if(v1[j].first%v1[j].second==0)
            continue;
        ll x = v1[j].first/v1[j].second;
        curr+=(((x+1)*v1[j].second)-v1[j].first);
        ans+=(((x+1)*v1[j].second)-v1[j].first);
    }
    cout<<ans<<endl;
    
    
    
    
      return 0;
}

Submission Info

Submission Time
Task A - Multiple Array
User StillHungry
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1628 Byte
Status AC
Exec Time 29 ms
Memory 2548 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 29 ms 2420 KB
02.txt AC 28 ms 2420 KB
03.txt AC 28 ms 2420 KB
04.txt AC 28 ms 2420 KB
05.txt AC 28 ms 2548 KB
06.txt AC 29 ms 2420 KB
07.txt AC 23 ms 2548 KB
08.txt AC 29 ms 2420 KB
09.txt AC 24 ms 2420 KB
10.txt AC 29 ms 2548 KB
11.txt AC 23 ms 2420 KB
12.txt AC 18 ms 2420 KB
13.txt AC 23 ms 2420 KB
14.txt AC 29 ms 2420 KB
15.txt AC 3 ms 256 KB
16.txt AC 3 ms 256 KB
s1.txt AC 3 ms 256 KB
s2.txt AC 3 ms 256 KB