Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

### liveoverflow's blog

By liveoverflow, history, 5 weeks ago, , There are 4 arrays of A, B, C, D of size N, we have to find

max( | A[i]-A[j] | + | B[i]-B[j] | + | C[i]-C[j] | + | D[i]-D[j] | + | i-j |)

where 1<=i<j<=n ; 1<N<=10^5; 1<=A[i],B[i],C[i],D[i]<=10^9

sample input :
5
5 7 6 3 9
7 9 2 7 5
1 9 9 3 3
8 4 1 10 5

sample output : 24 By liveoverflow, history, 7 weeks ago, , Q)subtract a digit from the given number (the digit must occur in the number) and get a new number. Repeat this operation until the number equals zero. count the minimum number of operations needed to reduce the number to zero.

submission link -> 80890640 for n = 1000000, the given code is giving segmentation fault but works well for other values. Please, anyone me help to get rid of this

vector<int>dp(1000000+1,1e9);
int f(int n){
if(dp[n]!=1e9) return dp[n];
int te = n;
while(te){
if(te%10!=0) dp[n]=min(dp[n],1+f(n-te%10));
te/=10;
}
return dp[n];
}
int main(){
int t=1; //cin>>t;
while(t--){
int n; cin>>n;
dp=0;
cout<< f(n);
}
} #dp,
By liveoverflow, history, 3 months ago, , Given $X,p,a,b$, we need to find out how many $n\in\mathbb N,\;(1\leqslant n\leqslant X)\;$ satisfy the following condition:

>

$na^n\equiv b\pmod{p}$

Constraints:

\begin{aligned}\begin{equation}2\leqslant p\leqslant 10^6\\1\leqslant a,b\lt p\\1\leqslant X\leqslant 10^{12}\end{equation}\end{aligned}

I have no idea how to solve this question, any approach or proof will be highly appreciated. By liveoverflow, history, 3 months ago, , Given are the 3 non-negative integers a,b,c

In a single operation, we have to subtract 1 from two integers only if they don't become negative.

We have to find the maximum no of operations possible that we can do until the given operation is not possible.

constraints:1<=a,b,c<=10^18 , 1<=test-cases<=10^5

Example- (1,2,3) = (1,1,2) -> (1,0,1) -> (0,0,0) , ans is 3

(1,1,8) = (1,0,7) -> (0,0,6) , ans is 2

Any approach or proof will be highly helpful.

I have actually written a code that's working as far as I know, but I don't know if it's completely true,

Thanks ~~~~~

#include<bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define LL long long

int main(){
fastio;
int t; cin>>t;
while(t--){
LL a; cin>>a>>a>>a;
sort(a,a+3);
if(a+a>=a){
LL ans = a + (a+a-a)/2;
cout<<ans;
}
else {
LL ans = a + min(a,a-a);
cout<<ans;
}
cout<<"\n";
}
}

~~~~~ By liveoverflow, history, 7 months ago, ,  #dp, #598,