├── .DS_Store
├── 00-Setting-up-local-environment
└── README.md
├── 01-Material
└── README.md
├── 02-Codes
├── .DS_Store
├── Editorials
│ ├── .DS_Store
│ ├── ConvertToStrictlyIncreasing
│ │ ├── ConevertToStrictlyIncreasing.md
│ │ ├── convertToIncreasing.cpp
│ │ └── convertToIncreasing.py
│ └── Random
│ │ └── TransposeColorsWork.cpp
├── README.md
└── Snippets
│ ├── .DS_Store
│ ├── Raw
│ └── 166_e_MatMul_w_Ashishgup.cpp
│ ├── Sublime
│ ├── .DS_Store
│ ├── FastReadWrite.sublime-snippet
│ ├── My Snippets not used now.tar.gz
│ ├── addundirectededge.sublime-snippet
│ ├── basic-template.sublime-snippet
│ ├── check execution time.sublime-snippet
│ ├── checkvalid.sublime-snippet
│ ├── cmp-priority.sublime-snippet
│ ├── common-completions.sublime-completions
│ ├── dsu-array.sublime-snippet
│ ├── dsu.sublime-snippet
│ ├── errorWatch.sublime-snippet
│ ├── eulerTotientFunc.sublime-snippet
│ ├── leetcode-solution-class.sublime-snippet
│ ├── manipulated-sieve-of-eratosthene.sublime-snippet
│ ├── matrix-expo.sublime-snippet
│ ├── max-biparite-matching.sublime-snippet
│ ├── modop.sublime-snippet
│ ├── myReadTemplate.sublime-snippet
│ ├── ncr-on-demand.sublime-snippet
│ ├── pbds.sublime-snippet
│ ├── power-expo.sublime-snippet
│ ├── sieve-of-eratosthene.sublime-snippet
│ └── topcoder-template.sublime-snippet
│ └── mydebug.h
├── 03-Interview Preparation
├── Docs
│ ├── .gitkeep
│ ├── 0x01_Interview_Preparation_in_C_v1.0.docx
│ └── System Design Guide.docx
├── PDF
│ ├── .gitkeep
│ ├── 0x01 C Interview Preparation-compressed.pdf
│ ├── Algorithm Analysis.pdf
│ ├── Computer networks- most asked interview questions.pdf
│ ├── DBMS Exclusive Notes.pdf
│ ├── LeetCode 50 Common Interview Questions with Solutions.pdf
│ ├── OOPs in C++.pdf
│ ├── Operating System Exclusive Notes. .pdf
│ └── SQL Exclusive Notes.pdf
└── README.md
└── README.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luctivud/All-Of-Competitive-Programming/0a8926089af68a439d78ea6c92281209af050222/.DS_Store
--------------------------------------------------------------------------------
/00-Setting-up-local-environment/README.md:
--------------------------------------------------------------------------------
1 | # Setting up Competitive Programming on Local Machine :
2 |
3 | #### Content
4 |
5 | - [Benefits](#Benefits)
6 |
7 | - [SetUp](#Setting-up-env)
8 |
9 | - [Snippets](#Snippets)
10 |
11 |
12 |
39 | 40 | 1. After solving a few examples on pen and paper, we get to see that a greedy solution would fail on cases like [8, 1, 2, 3, 4] or [7, 1, 5, 2, 4, 8, 6]. 41 | 42 | 2. Another key observation is that in the transformed array which is strictly increasing, we will find that there is atleast one element which remains unchanged. 43 |
44 | 45 |75 | DP transition states: 76 | 77 | - **dp[j] = min(dp[j-1], dp[j] + abs(A[i] - B[j]))** ∀ i, j ∈ [1, N]. 78 | 79 | Please note that the array **A** here is the converted array represented by (Ai-i) ∀ i ∈ [1, N] and **B** is its sorted version. 80 | 81 | Our final answer that represents the minimum cost is stored in the final index of our **dp** array which represents the optimal array till last index of **A**. 82 |
83 | 84 | If our minimum cost is not more than **K** then we can certainly achieve the optimal solution. 85 | 86 | Note : This dp solution can be made more state verbose by storing the brute forced optimal substructure into their respective states in dp[i][j] but I prefer it this way. 87 | 88 |91 | 92 | ```python 93 | N = int(input()) 94 | K = int(input()) 95 | A = [0] + list(map(int, input().split())) 96 | 97 | # Convert A[i] = A[i] - i 98 | for i in range(1, N+1): 99 | A[i] = A[i] - i 100 | 101 | # store sorted A in B to stay working 102 | # with best possible element already 103 | B = [0] + sorted(A[1:]) 104 | 105 | # dp array 106 | dp = [0 for x in range(N+1)] 107 | 108 | # unreachable state 109 | dp[0] = float('inf') 110 | 111 | for i in range(1, N+1): 112 | for j in range(1, N+1): 113 | dp[j] = min(dp[j-1], dp[j] + abs(A[i] - B[j])) 114 | 115 | 116 | # dp[N] represent the ans 117 | print("YES "+str(dp[N]) if dp[N] <= K else "NO") 118 | ``` 119 | 120 |
121 |
126 |
127 | ```cpp
128 | #include
Check the subfolders for contents, it has some snippets and editorials
4 | -------------------------------------------------------------------------------- /02-Codes/Snippets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luctivud/All-Of-Competitive-Programming/0a8926089af68a439d78ea6c92281209af050222/02-Codes/Snippets/.DS_Store -------------------------------------------------------------------------------- /02-Codes/Snippets/Raw/166_e_MatMul_w_Ashishgup.cpp: -------------------------------------------------------------------------------- 1 | // J A I S H R E E R A M // 2 | 3 | #include