Submission #1073877


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define err(x) cout<<#x<<"= "<<x<<endl;
#define FOR(i,a,b) for(int i =a; i< b; ++i)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define INF 1000000000
#define TRVI(it,it1,it2) for(vi::iterator it = it1; it!= it2; it++)
#define ff first
#define ss second
#define mp make_pair
#define pq priority_queue<int, vector<int>, greater<int> >
#define ll long long
const ll PR = 1000000009;
#define SIZE 1
#define vi vector<ll>
#define pii pair<int,int>
#define endl '\n'

int main(){
//	#ifdef ONLINE_JUDGE
//	freopen("a.in", "r" , stdin);
//	freopen("a.out", "w", stdout);
//      cin.tie(false); cout.tie(false);	
//	#endif
	ios::sync_with_stdio(false);
	ll n;
	vi A,B;
	cin>>n;
	for(int i =0; i< n; i++){
		int a,b;
		cin>>a>>b;
		A.pb(a);
		B.pb(b);
	}
	ll ans =0;
	for(int i = n-1; i>= 0; i--){
		ll now = A[i]+ans;
		ll rem = B[i] - now%B[i];
		if(rem == B[i])rem = 0;
		ans+= rem;
//		cout<<now<<' '<<B[i]<<' '<<rem<<endl;
	}
	cout<<ans<<endl;
	return 0;
};

Submission Info

Submission Time
Task A - Multiple Array
User Dipak
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1050 Byte
Status AC
Exec Time 31 ms
Memory 2164 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 30 ms 2036 KB
02.txt AC 29 ms 2036 KB
03.txt AC 30 ms 2036 KB
04.txt AC 30 ms 2036 KB
05.txt AC 30 ms 2036 KB
06.txt AC 30 ms 2036 KB
07.txt AC 25 ms 2164 KB
08.txt AC 31 ms 2036 KB
09.txt AC 25 ms 2036 KB
10.txt AC 30 ms 2036 KB
11.txt AC 24 ms 2036 KB
12.txt AC 20 ms 2036 KB
13.txt AC 24 ms 2036 KB
14.txt AC 31 ms 2164 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