DELISH - Editorial

Well, @devanshug, you’re right and it is indeed a lot better now than it was before… I even got to write some Simple problems as a setter and I actually think I managed to write good tutorials here on forums… But sometimes I feel that this is all I got… Maybe it’s the lack of time that makes me think this way, but it’s still very frustrating and demotivating… I think I will try to work as hard as university allows me, in order to get a little bit better though :slight_smile: Thanks for your words

1 Like

dafaq is this code !!!whre’s a main() ??

1 Like

@kuruma, Being relatively new to competitive programming and algorithms besides the constraints due to university, i feel the same as i have not been able to solve more than 3 problems but each time we get stuck we learn something new(be it the simplest of things) but that is what should drive us as these little things go a long way in enhancing our programming skills. Bit by Bit, Bytes of knowledge can be acquired, learnt and applied to improve our speed and efficiency in solving more problems. And considering that you are a lot better than before, its an achievement in itself. Chin up!

2 Likes

@spandanpathak, It has a main… but nothing else is understandable. Probably we first need to replace all those variable to simple ones and the format it to understand where the functions start and end… :stuck_out_tongue:

That code gives me urges that he must have done something which he is hiding behind that dirty code :slight_smile:

1 Like

@shashank_jain: I always prefer akash4983’s code for this purpose . least use of templates , least use of all the big constructs and more of a simple oriented approach devoid of problems associated with using abs , fabs , mods etc.

It’s natural to feel this way maybe you were trying too hard…but as @devanshug said compare your knowledge now with what you have when you started…Key is to keep practicing…and C’mon you are the one who wrote questions like FCBARCA and CLBMSTRS which I loved to solve…these are way too creative…simple series questions hidden behind very creatively created stories…AWESOME MAN AWESOME!!! Happy Coding:-)

2 Likes

The code seems to be the output of a decompiler or obfuscator. Some reasons which come to my mind are either he would have done it to optimise the code (eg, compile with gcc -O3 and then decompile) or maybe he cheated from someone else so to make the code look different obfuscated it.

1 Like

Nice work, I’ve also seen some of your tutorials and one time you even explained a problem to me. You have really nice logic, I think if you don’t give up you’ll become a really strong competitor and be able to fight for the first spots. Also, I’ve seen you complain a lot about math basis but you shouldn’t let it stop you from solving problems. If you do that you’ll just be wasting your talent, we should turn our weaknesses into our greatest strengths. In no way I’m saying this to only encourage you, I say this because it’s true.

4 Likes

Thanks @junior94, I hope that if I stick around this community my knowledge can grow much, much more and I can grow as a coder and as a person as well :smiley:
Everyone’s words are a great motivating factor and hopefully things will go better on next month or at least as good as they went on this one :slight_smile:

Your solution is very neat but with an observation you could dove done it a lot cleaner. Think about reversing the array after finding the frist min and max.

Maybe then it’s possible to use only 2 arrays instead of four?

I was aiming to the fact that you could’ve used the first two methods for the other calculations aswell,

I guess he used some translation tool (between programming languages) or other.
After doing below conversion(and formatting a little), the code will be fine.
Though the basic idea is the same as mine, his implementation is simpler.
I fun to work out this puzzle :slight_smile:
(i_d6->readingBuff),(i_d8->readInt),
(i_d12,i_d13,i_d14,i_d15: non-use),
(i_d9->sign),(i_d10->value),(i_d11->ch),
(i_d7->curChPtr),(i_d18->testCase),
(i_d19->i),(i_d20->N),(i_d22->D),(i_d21->maxV),
(i_d23->sumMaxL),(i_d24->sumMaxR),(i_d25->sumMinL),(i_d26->sumMinR),
(i_d27->pLL),(i_d28->endD),("\45\154\154\144\n"->"%lld\n")

2 Likes

This could be the sequence: 10+3-1=12, or 10+3+1-2=12

res* = 0;

I see that this means res[i] = 0; but how is this valid syntax? It gives compilation error in gcc at least.

@admin
I had a different approach to this problem. I applied greedy solution. Why cant we just sort and do it.

https://www.codechef.com/viewsolution/26496390

I am getting WA but my solution is correct.
I dont know why i am gettin WA.

1 Like

Do Check out This, Its explained in very simple language there! :smiley:

Nice tutorial for DP. Accepted :slightly_smiling_face:

Here is my easy to read code:

/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                   ____/`---'\____
                  /  \\|     |//  \
                 / \\||| /:\ |||// \
                / _||||| -:- |||||- \
               |   | \\\ \-/ /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
            ____'. .'  /--.--\  `. .'_____
          /"" '<  `.___\_<|>_/___.' >' "" \
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` / _/
          `-.____`.___ \_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    ADITI GOEL IS LOVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define umii unordered_map<int64_t,int64_t>
#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<"\nhi"<<x<<"\n"
#pragma GCC optimize ("unroll-loops")
#define fii for(i=1;i<=n;i++)
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define vi vector<int>
#define eb emplace_back
#define nl cout<<"\n"
#define int int64_t
#define pb push_back
#define sp <<" "<<
#define se second
#define fi first
#define mod 2147483647
#define LIM 200005
using namespace std;
 
int fpow( int x,int y)
{
    int temp;
    if(y == 0)
        return 1;
    temp = fpow(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
 
 
int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
 
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

int cnt, sum = 0, mid, mx = -1e17, mn = 1e17;
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;


//***************************************************************************************************************************************



int32_t main() {    fio;     double tt = clock();

     ftt{
          cin>>n;
          int a[n+3];
          int mxt[n+3],mnt[n+3],mxf[n+3],mnf[n+3];
          
          //mxt : max sum till
          //mxf : max sum from
          //mnt : min sum till
          //mnf : min sum from
          
          
          fii cin>>a[i];
          
          mx=-1e15;
          sum=-1e15;
          fii{
               sum=max(sum+a[i],a[i]);
               mx=max(mx,sum);
               mxt[i]=mx;
          }
          
          mn=1e15;
          sum=1e15;
          fii{
               sum=min(sum+a[i],a[i]);
               mn=min(mn,sum);
               mnt[i]=mn;
          }
          
          reverse(a+1, a+n+1);
          
          mx=-1e15;
          sum=-1e15;
          fii{
               sum=max(sum+a[i],a[i]);
               mx=max(mx,sum);
               mxf[n-i+1]=mx;
          }
          
          mn=1e15;
          sum=1e15;
          fii{
               sum=min(sum+a[i],a[i]);
               mn=min(mn,sum);
               mnf[n-i+1]=mn;
          }
          
          int ans=-1e16;
          
          for(i=1;i<n;i++){
               ans=max(ans,max(abs(mxt[i]-mnf[i+1]),abs(mnt[i]-mxf[i+1])));
               
          }
          cout<<ans;nl;
          
     }
     
     
     cerr << "\nTIME = " << (clock() - tt)/CLOCKS_PER_SEC <<"seconds\n";
}