Count K-Subsequences of a String with Maximum Beauty Solution || Leetcode Bi-Weekly 112 Get link Facebook X Pinterest Email Other Apps - September 04, 2023 Count K-Subsequences of a String with Maximum Beauty Get link Facebook X Pinterest Email Other Apps
Plusle and Minun on Array Solution || Codechef Starters - 29 Get link Facebook X Pinterest Email Other Apps - March 09, 2022 Plusle and Minun on Array Solution Codechef Starters - 29Problem Code : PMAProblem Link : https://www.codechef.com/START29C/problems/PMASolution :#include <bits/stdc++.h>#define ll long long int#define ull unsigned long long intusing namespace std;ll maxe(ll a[], ll n){ ll ans = a[1]; for (ll i = 1; i < n; i += 2) { if (a[i] > ans) ans = a[i]; } return ans;}ll mine(ll a[], ll n){ ll ans = a[0]; for (ll i = 0; i < n; i += 2) { if (a[i] < ans) ans = a[i]; } return ans;}void solve(){ ll n; cin >> n; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; if (a[i] < 0) { a[i] = -1 * a[i]; } } ll first = maxe(a, n); ll second = mine(a, n); ll ans1 = 0; for (ll i = 0; i < n; i++) { if (i % 2 == 0) { ans1 += a[i]; } else { ans1 -= a[i]; } } ll ans2 = ans1 + 2 * first - 2 * second; cout << max(ans1, ans2) << "\n";}int main(){ ll t; cin >> t; while (t--) { solve(); }} Get link Facebook X Pinterest Email Other Apps Comments
Exact Marks Solution || Codechef March Long Challenge 2022 - I - March 11, 2022 Exact Marks Solution Read more
Substring of a Substring Solution || Codechef March Long Challenge 2022 - I - March 11, 2022 Substring of a Substring Solution Read more
Binary Base Basics Solution || Codechef February Long Challenge 2022 - I - February 04, 2022 Binary Base Basics Solution Read more
Comments
Post a Comment