why is sum(|p-q|) smallest when we subtract in decreasing order?
@ashishcode2 жыл бұрын
If you sort an array in any order, the difference between adjacent elements will be the minimum possible. I have done in descending as I wanted the max first.
@arjavrastogi92592 жыл бұрын
@@ashishcode Thanks✌
@pial94838 ай бұрын
#include #define ll long long using namespace std; const int mx = 150005; int BIT[mx]; int main() { ll T; cin>>T; while(T--) { ll n; cin >> n; // Initialize the BIT array //memset(BIT, 0, sizeof(BIT)); vector bal(n); for(ll i=0; i>bal[i]; } string s; cin>>s; ll sz=s.size(); ll one=count(s.begin(),s.end(),'1'); ll zro=count(s.begin(),s.end(),'0'); vectorzerobal,onebal; //cout
@yashkhatwani31982 жыл бұрын
Thanks amazing explaination
@vaibhavsingh60352 жыл бұрын
great sir , I have tried this question a lot but getting tle
@nopecharon2 жыл бұрын
good explanation thank you
@dhirajthorat69652 жыл бұрын
great explanation sir!
@uu-wl8gw2 жыл бұрын
Can u tell me what does "p is a permutation" means?
@ashishcode2 жыл бұрын
Permutation means it contains all the values from 1 to n exactly once, in any order.