Submission #19348036


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--) 

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL);

	long long int a, b;
	cin>>a>>b;
	long long int c[a], d[a], e[a], mx=0, ss=0, mn=LLONG_MAX;
	unsigned long long int ans=0;
	map<long long int, long long int> arr, arr2;
	forr(i, 0, a)
	{
		long long int x, y, z;
		cin>>x>>y>>z;
		c[i]=x, d[i]=y, e[i]=z;
		x=z;
		mx=max(mx, c[i]);
		mx=max(mx, d[i]);
		mn=min({mn, c[i], d[i]});
		arr[c[i]]+=x;
		arr[d[i]+1]-=x;
	}	
	vector<pair<long long int, long long int>> v;
	set<pair<long long int, long long int>> s;
	for(auto const x: arr)
	{
		s.insert({x.first, x.second});
	}
	for(auto const x: s)
		v.push_back({x.second, x.first});
	long long int diff=v[0].first;
	forr(i, 1, v.size())
	{
		long long int diff2=diff, n=v[i].second-v[i-1].second;
	//	cout<<diff<<' '<<n<<"\n";
		ans+=(min(n*diff2, b*n));
		diff=v[i].first+diff2;
	}
	if(ans<0)
	{
		ans=b*(mx-mn+1);		
	}
	cout<<ans;
	

	return 0;
}

Submission Info

Submission Time
Task D - Snuke Prime
User jack07
Language C++ (GCC 9.2.1)
Score 0
Code Size 1121 Byte
Status WA
Exec Time 501 ms
Memory 66076 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:3:49: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    3 | #define forr(i,a,n)     for(long long int i=a; i<n; i++)
......
   36 |  forr(i, 1, v.size())
      |       ~~~~~~~~~~~~~~                             
./Main.cpp:36:2: note: in expansion of macro ‘forr’
   36 |  forr(i, 1, v.size())
      |  ^~~~
./Main.cpp:43:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   43 |  if(ans<0)
      |     ~~~^~
./Main.cpp:12:28: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]
   12 |  long long int c[a], d[a], e[a], mx=0, ss=0, mn=LLONG_MAX;
      |                            ^
./Main.cpp:12:40: warning: unused variable ‘ss’ [-Wunused-variable]
   12 |  long long int c[a], d[a], e[a], mx=0, ss=0, mn=LLONG_MAX;
      |                                        ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 27
WA × 1
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 7 ms 3456 KB
random_02.txt AC 2 ms 3464 KB
random_03.txt AC 3 ms 3404 KB
random_04.txt AC 2 ms 3388 KB
random_05.txt AC 3 ms 3488 KB
random_06.txt AC 2 ms 3400 KB
random_07.txt AC 2 ms 3452 KB
random_08.txt AC 2 ms 3484 KB
random_09.txt AC 2 ms 3408 KB
random_10.txt AC 2 ms 3404 KB
random_11.txt AC 2 ms 3428 KB
random_12.txt AC 2 ms 3456 KB
random_13.txt AC 3 ms 3480 KB
random_14.txt AC 3 ms 3480 KB
random_15.txt AC 3 ms 3500 KB
random_16.txt AC 108 ms 20220 KB
random_17.txt AC 245 ms 37524 KB
random_18.txt AC 211 ms 33620 KB
random_19.txt AC 188 ms 31428 KB
random_20.txt AC 473 ms 65572 KB
random_21.txt AC 353 ms 50716 KB
random_22.txt AC 37 ms 9092 KB
random_23.txt AC 501 ms 66036 KB
random_24.txt AC 481 ms 66076 KB
random_25.txt WA 58 ms 8092 KB
sample_01.txt AC 3 ms 3400 KB
sample_02.txt AC 3 ms 3340 KB
sample_03.txt AC 2 ms 3484 KB