kiwirafe.blog

SCPC Week 7 Tutorial

The 67th 6-7 Integer Problem

Original Problem Link: https://codeforces.com/contest/2218/problem/B

#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
typedef long long ll;
 
void solve() {
    int num;
    int sum_num = 0;
    int max_num = INT_MIN;
    for (int i = 0; i < 7; i++) {
        cin >> num;
        sum_num += num;
        max_num = max(max_num, num);
    }
 
    cout << 2 * max_num - sum_num << endl;
}
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; 
    cin >> t;
    while (t--) solve();
}

Angry Kavya

Original Problem Link: https://codeforces.com/contest/1992/problem/B

#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
typedef long long ll;
 
void solve() {
    int n, k;
    cin >> n >> k;
    
    ll num;
    ll ans = 0;
    ll max_num = 0;
    for (int i = 0; i < k; i++) {
        cin >> num;
        if (num > 1)
            ans += 2 * (num - 1);

        max_num = max(max_num, num);
    }
 
    cout << ans - 2 * (max_num - 1) + (k - 1) << endl;
}
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; 
    cin >> t;
    while (t--) solve();
}

RemovevomeR

Original Problem Link: https://codeforces.com/contest/2241/problem/C

#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
typedef long long ll;
 
void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
 
    char last = s[0];
    int components = 1;
    for (int i = 1; i < n; i++) {
        if (s[i] != last) {
            last = s[i];
            components += 1;
        }
    }
    
    if (components != 2)
        cout << 1 << endl;
    else
        cout << 2 << endl;
}
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; 
    cin >> t;
    while (t--) solve();
}

The Hedgehog’s Dilemma

Original Problem Link: https://codeforces.com/contest/2218/problem/D

Prefix Sum Solution:

#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
typedef long long ll;
 
void solve() {
    int n;
    cin >> n;
 
    ll num = 1;
    for (int i = 0; i < n; i++) {
        cout << num * (num + 2) << ' ';
        num += 2;
    }
 
    cout << endl;
}
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; 
    cin >> t;
    while (t--) solve();
}

Cinnamon the Cat

Original Problem (Adapted from NZOI Training Site)

#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
typedef long long ll;
 
void solve() {
    int n; cin >> n;
 
    int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        cin >> c;
        sum = max({sum1 + a + b + c, sum2 + b + c, sum3 + c, sum4});
        a = b, b = c;
        sum1 = sum2, sum2 = sum3, sum3 = sum4, sum4 = sum;
    }
 
    cout << sum << endl;
    
}
 
int main() {
    solve();
 
    return 0;
}