WhiteHat Coding
Ir al canal en Telegram
650
Suscriptores
Sin datos24 horas
-27 días
-330 días
Archivo de publicaciones
import java.util.*;
public class Solution {
public int minimizeTravelTax(int A, int[][] B, int[][] C, int[] D) {
List<Integer>[] adj = new List[A+1];
for (int i = 1; i <= A; i++) {
adj[i] = new ArrayList<>();
}
for (int i = 0; i < B.length; i++) {
int u = B[i][0];
int v = B[i][1];
adj[u].add(v);
adj[v].add(u);
}
int[] dp1 = new int[A+1];
int[] dp2 = new int[A+1];
dfs(1, 0, adj, D, dp1, dp2);
int ans = 0;
for (int i = 0; i < C.length; i++) {
int s = C[i][0];
int t = C[i][1];
int lca = findLca(s, t, adj);
int tax = dp1[s] + dp1[t] - 2 * dp1[lca];
if (D[lca] % 2 == 0) {
tax -= dp2[lca];
}
ans += tax;
}
Minimize Travel Tax
Java✅
share @whitehatcoding ❤️
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> k(n), h(n);
for (int i = 0; i < n; i++) {
cin >> k[i];
}
for (int i = 0; i < n; i++) {
cin >> h[i];
}
vector<pair<int, int>> st;
for (int i = 0; i < n; i++) {
st.push_back({k[i] - h[i], k[i]});
}
sort(st.begin(), st.end());
int l = -1, r = -1, ans = 0;
for (auto it : st) {
if (it.first >= r) {
ans += (r - l) * (r - l + 1) / 2;
l = it.first;
r = it.second;
}
else {
r = max(r, it.second);
}
}
ans += (r - l) * (r - l + 1) / 2;
cout << ans << endl;
}
return 0;
}
C++
Find the evil monster code
for _ in range(int(input())):
n = int(input())
k = list(map(int, input().split()))
h = list(map(int, input().split()))
st = []
for i in range(n):
st.append([k[i] - h[i], k[i]])
st.sort()
l, r = -1, -1
ans = 0
for it in st:
if it[0] >= r:
ans += (r - l) * (r - l + 1) // 2
l, r = it
else:
r = max(r, it[1])
ans += (r - l) * (r - l + 1) // 2
print(ans)
Trilogy Code ❤️✅
python
def minimum_chunks(n, cards):
stack = []
chunks = 0
for card in cards:
if not stack or card > stack[-1][-1]:
stack.append([card])
else:
seq = []
while stack and card <= stack[-1][-1]:
seq.extend(stack.pop())
seq.append(card)
stack.append(seq)
chunks += 1
chunks += len(stack)
return chunks
n = int(input())
cards = list(map(int, input().split()))
print(minimum_chunks(n, cards))
Keep Sharing guys!! ❤️😊
For Free Solutions.
More Members -> More Solutions!!
Share @Whitehatcoding ❤️
To remove Plagiarism🟥🟨🟧🟩🟦🟪
1) Use your Own template✅
2) Change Variables ✅
3) Try to read input in unique style✅
4) Understand the code and write in your style ✅
5) Write whole code in main function / write in diffrent function✅
6) Change Function name solve()=> unique✅
7) If possible change flow of the problem (if it doesn't impact the logic of code)✅
there are so many other things to avoid Plagiarism🔥🔲
@whitehatcoding ❤️
Any exam help send the link...
before u apply...i will send ans...here.❤️
share @whitehatcoding ✅
Guys IF you want help any exams send the exams links also before u apply so that i will send answers here.....😍😅
2023 Batch Guys 👨💻
n,k=map(int,input().split())
l=[int(z) for z in input().split()][::-1]
print(l.index(k)+1)
Last occurance code python✅
share @whitehatcoding ❤️
public class Solution {
public ArrayList<Integer> monsterDefeated(int[][] A, int[][] B) {
int n = A.length;
int q = B.length;
int[] monsterCount = new int[100001];
long totalMonsters = 0;
ArrayList<Integer> result = new ArrayList<>();
// Count the monsters at each coordinate
for (int i = 0; i < n; i++) {
for (int j = A[i][0]; j <= A[i][1]; j++) {
monsterCount[j] += A[i][2];
totalMonsters += A[i][2];
}
}
// Sort the heroes by their coordinates
Arrays.sort(B, (a, b) -> Integer.compare(a[0], b[0]));
// Calculate the remaining monsters after each hero
long monstersDefeated = 0;
for (int i = 0; i < q; i++) {
int heroCoord = B[i][0];
int heroStrength = B[i][1];
// Defeat monsters up to the hero's strength
while (monstersDefeated < totalMonsters && monsterCount[heroCoord] > 0 && heroStrength > 0) {
int monstersAtCoord = monsterCount[heroCoord];
int monstersDefeatedByHero = Math.min(monstersAtCoord, heroStrength);
monsterCount[heroCoord] -= monstersDefeatedByHero;
monstersDefeated += monstersDefeatedByHero;
heroStrength -= monstersDefeatedByHero;
}
// Add the remaining monsters to the result
result.add((int) (totalMonsters - monstersDefeated));
}
return result;
}
}
