Submission #12138174


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e9
#define MOD (1000000000+7)

signed main()
{
    int n, k;
    cin >> n >> k;

    int ans = 0;
    int min_s = 0;
    int max_s = 0;
    for(int i = 0;i < k;i++){
        min_s += i;
        max_s += n - i;
    }
    //cout << min_s << ' ' << max_s<<endl;
    ans = (ans%MOD + (max_s%MOD - min_s%MOD) + 1) % MOD;
    //cout << ans <<endl;

    for(int i = k+1;i <= n + 1;i++){
        min_s += i - 1;
        max_s += n - i + 1;
        /*
        for(int j = 0;j < i;j++){
            min_s += j;
            max_s += n - j;
            //cout << j << endl;
        }
        */
        //cout << min_s << ' ' << max_s<<endl;
        //cout << max_s - min_s + 1 << endl;
        ans = (ans%MOD +(max_s - min_s) + 1) % MOD;
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - Sum of Large Numbers
User kotatsumuri
Language C++ (GCC 9.2.1)
Score 400
Code Size 877 Byte
Status AC
Exec Time 7 ms
Memory 3624 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All hand_01, hand_02, max_01, max_02, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
hand_01 AC 7 ms 3624 KiB
hand_02 AC 2 ms 3564 KiB
max_01 AC 2 ms 3600 KiB
max_02 AC 3 ms 3564 KiB
random_01 AC 3 ms 3596 KiB
random_02 AC 2 ms 3564 KiB
random_03 AC 2 ms 3444 KiB
random_04 AC 4 ms 3596 KiB
random_05 AC 2 ms 3436 KiB
random_06 AC 2 ms 3588 KiB
random_07 AC 3 ms 3440 KiB
random_08 AC 3 ms 3444 KiB
random_09 AC 3 ms 3584 KiB
random_10 AC 2 ms 3568 KiB
random_11 AC 2 ms 3404 KiB
random_12 AC 4 ms 3568 KiB
sample_01 AC 2 ms 3568 KiB
sample_02 AC 2 ms 3436 KiB
sample_03 AC 3 ms 3624 KiB