Submission #19359107


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   fastIO
   int n,y; cin>>n>>y;
   map<int,int> mp;
   int ans=0;
   rep(i,0,n){
     int a,b,c; cin>>a>>b>>c;
     mp[a]+=c;
     mp[b+1]-=c;
   }
   int prev=-1;
   rr(mp){
      if(prev!=-1){
        ans+=(val.fi-prev)*y;
      }
      prev=val.fi;
   }
   prev=-1;
   rr(mp){
      if(prev!=-1){
        if(y>mp[prev])ans-=(val.fi-prev)*y,ans+=(val.fi-prev)*mp[prev];
        val.se+=mp[prev];
      }
      prev=val.fi;
   }
   cout<<ans<<"\n";
   return 0;
}

Submission Info

Submission Time
Task D - Snuke Prime
User nagaraj41
Language C++ (GCC 9.2.1)
Score 400
Code Size 1593 Byte
Status AC
Exec Time 393 ms
Memory 28584 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 1 ms 3516 KB
random_02.txt AC 2 ms 3524 KB
random_03.txt AC 2 ms 3556 KB
random_04.txt AC 2 ms 3588 KB
random_05.txt AC 2 ms 3576 KB
random_06.txt AC 2 ms 3568 KB
random_07.txt AC 3 ms 3412 KB
random_08.txt AC 2 ms 3520 KB
random_09.txt AC 2 ms 3524 KB
random_10.txt AC 2 ms 3476 KB
random_11.txt AC 2 ms 3476 KB
random_12.txt AC 3 ms 3472 KB
random_13.txt AC 2 ms 3412 KB
random_14.txt AC 2 ms 3412 KB
random_15.txt AC 2 ms 3580 KB
random_16.txt AC 79 ms 10456 KB
random_17.txt AC 181 ms 17340 KB
random_18.txt AC 170 ms 15656 KB
random_19.txt AC 142 ms 14544 KB
random_20.txt AC 393 ms 28324 KB
random_21.txt AC 269 ms 21584 KB
random_22.txt AC 32 ms 5844 KB
random_23.txt AC 364 ms 28584 KB
random_24.txt AC 385 ms 28532 KB
random_25.txt AC 51 ms 3476 KB
sample_01.txt AC 2 ms 3472 KB
sample_02.txt AC 2 ms 3476 KB
sample_03.txt AC 2 ms 3540 KB