Submission #19339488


Source Code Expand

Copy
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
using namespace std;
#define Fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr)
#define f(i, n) for (long long int i = 0; i < n; i++)
#define ll long long int
#define fo(i, a, b) for (long long int i = a; i <= b; i++)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<long long int>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
#define MAX 1000005 

ll mini(ll a,ll b){
    if(a>=b)return b;
    return a;
}

ll maxi(ll a,ll b){
    if(a>=b)return a;
    return b;
}


int main(){
	Fio;
    ll n,C;
    cin>>n>>C;
    ll ans = 0;
    set<ll>S;
    mll M;

    fo(i,1,n){
        ll a,b,c;
        cin>>a>>b>>c;
        ans += (b-a+1)*c;
        M[a]+=c;
        M[b+1]-=c;
        S.insert(a),S.insert(b+1);
    }
    ll prev = 0;
    multiset<pair<ll,pair<ll,ll>>>P;
    for(auto x: S){
        M[x]+=M[prev];
        P.insert(mp(M[prev],mp(prev,x-1)));
        prev = x;
    }
    for(auto x: P){
        if(x.fi>C){
            ans -= x.fi*(x.se.se-x.se.fi+1);
            ans += C*(x.se.se-x.se.fi+1);
        }
    }
    cout<<ans;
    return 0;
}

Submission Info

Submission Time
Task D - Snuke Prime
User loop_oops
Language C++ (GCC 9.2.1)
Score 400
Code Size 2003 Byte
Status AC
Exec Time 685 ms
Memory 72208 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 6 ms 3384 KB
random_02.txt AC 2 ms 3548 KB
random_03.txt AC 2 ms 3316 KB
random_04.txt AC 2 ms 3472 KB
random_05.txt AC 2 ms 3428 KB
random_06.txt AC 2 ms 3396 KB
random_07.txt AC 2 ms 3552 KB
random_08.txt AC 2 ms 3472 KB
random_09.txt AC 2 ms 3448 KB
random_10.txt AC 2 ms 3440 KB
random_11.txt AC 2 ms 3552 KB
random_12.txt AC 2 ms 3472 KB
random_13.txt AC 2 ms 3448 KB
random_14.txt AC 2 ms 3508 KB
random_15.txt AC 2 ms 3444 KB
random_16.txt AC 141 ms 22316 KB
random_17.txt AC 325 ms 41588 KB
random_18.txt AC 273 ms 36672 KB
random_19.txt AC 242 ms 33960 KB
random_20.txt AC 685 ms 71684 KB
random_21.txt AC 439 ms 52912 KB
random_22.txt AC 50 ms 9616 KB
random_23.txt AC 663 ms 72200 KB
random_24.txt AC 669 ms 72208 KB
random_25.txt AC 52 ms 3480 KB
sample_01.txt AC 2 ms 3484 KB
sample_02.txt AC 3 ms 3400 KB
sample_03.txt AC 2 ms 3400 KB