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

• -10

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]=0;
cout<< f(n);
}
}


• -12

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}$$2\leqslant p\leqslant 10^6\\1\leqslant a,b\lt p\\1\leqslant X\leqslant 10^{12}$$\end{aligned}

I have no idea how to solve this question, any approach or proof will be highly appreciated.

• -8

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[3]; cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
if(a[0]+a[1]>=a[2]){
LL ans = a[2] + (a[0]+a[1]-a[2])/2;
cout<<ans;
}
else {
LL ans = a[1] + min(a[0],a[2]-a[1]);
cout<<ans;
}
cout<<"\n";
}
}

~~~~~

• 0

By liveoverflow, history, 7 months ago, ,

I am trying to solve a problem, but getting WA.

I could not find out the reason why. Here is my code: Submission 65502511 Can you suggest any reasons? Thank you!