/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 588.0 KiB
#2 Wrong Answer 14ms 580.0 KiB
#3 Wrong Answer 21ms 836.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Endl '\n'
#define endl '\n'
#define nl '\n'
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define cinall(v)        \
    for (auto &&itt : v) \
    cin >> itt
#define coutall(v)       \
    for (auto &&itt : v) \
    cout << itt << ' '
using namespace std;

// vector<int> primes;
// bool is_prime[(int)1e7 + 10];
// seive here
// void seive()
// {
//     is_prime[0] = is_prime[1] = 1;
//     for (int i = 4; i <= 1e7 + 10; i += 2)
//     {
//         is_prime[i] = 1;
//     }
//     for (int i = 3; i * i <= 1e7 + 10; i += 2)
//     {
//         if (is_prime[i] == 0)
//         {
//             for (int j = i + i; j <= 1e7 + 10; j += i)
//             {
//                 is_prime[j] = 1;
//             }
//         }
//     }

//     //for finding primes in a single vector
//     for (int i = 0; i <= 1e7 + 10; i++)
//     {
//         if (is_prime[i] == 0)
//         {
//             primes.push_back(i);
//         }
//     }
//     for(int i = 0; i <= 100; i++){
//         cout << primes[i] << ' ';
//     }
//     return;
// }

void solve();

ll power(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll res = power(a, b / 2);
    if (b % 2)
    {
        return res * res * a;
    }
    return res * res;
}

void divsprint(ll n)
{
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
            {
                cout << i << ' ';
            }
            else
            {
                cout << i << ' ' << n / i << ' ';
            }
        }
    }
}

int myGcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    return myGcd(a, a % b);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // seive();
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // cout<<"Case "<<i<<": ";
        solve();
    }
}

void solve()
{
    int n, k; cin >> n >> k;
    vector<int> vect(n); cinall(vect);
    int curr_sum = 0;
    for(int i = 0; i < k; i++){
        curr_sum += vect[i];
    }
    // cout << "->" << curr_sum << '\n';
    int l = 0, r = k - 1;
    int res = INT32_MAX;
    if(k == 1){
        cout << *min_element(all(vect)) << '\n';
        return;
    }
    while(1){
        if(r == n) break;
        int tem = res;
        res = min(res, curr_sum);
        if(l > 0){
            int lef = curr_sum;
            lef = lef - vect[l] + vect[l - 1];
            res = min(res, lef);
        }
        if(r < n - 1){
            int rig = curr_sum;
            rig = rig - vect[r] + vect[r + 1];
            res = min(res, rig);
        }
        r++, l++;
        if(r == n) break;
        curr_sum = curr_sum - vect[l - 1] + vect[r];
    }
    cout << res << '\n';
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 06:00:15
Judged At
2024-12-09 06:00:15
Judged By
Score
1
Total Time
21ms
Peak Memory
836.0 KiB