Submission #1002769

# Submission time Handle Problem Language Result Execution time Memory
1002769 2024-06-19T19:30:43 Z Lobo Autobahn (COI21_autobahn) C++17
0 / 100
474 ms 431684 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

int main() {
	// #ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
	// #endif

	int n,k,x;
	map<int,vector<pair<pair<int,int>,int>>> eve;
	cin >> n >> k >> x;
	for(int i = 0; i < n; i++) {
		int l,r,t;
		cin >> l >> t >> r;
		eve[l].pb(mp(mp(l,+1),0));
		eve[r+1].pb(mp(mp(r+1,-1),0));
		if(l+t < r+1) {
			eve[l+t].pb(mp(mp(l+t,+1),1));
			eve[r+1].pb(mp(mp(r+1,-1),1));
		}
	}

	int ant = 0;
	vector<pair<pair<int,int>,int>> extras;
	int people = 0;
	int extra = 0;
	for(auto X : eve) {
		int tempo = X.fr;
		if(people >= k) {
			// ant,tempo-1
			extras.pb(mp(mp(ant,tempo-1),extra));
		}
		ant = tempo;
		for(auto XX : eve[tempo]) {
			int val = XX.fr.sc;
			if(XX.sc == 0) {
				people+= val;
			}
			else {
				extra+= val;
			}
		}
	}

	int ans = 0;
	int sumtot = 0;
	// nao pego nem le nem re inteiros por padrao
	int re = 0;
	for(int le = 0; le < extras.size(); le++) {
		// cout << extras[le].fr.fr << " " << extras[le].fr.sc << " " << extras[le].sc << endl;
		int l = extras[le].fr.fr;
		int r = l+x-1;
		while(re+1 < extras.size() && r >= extras[re+1].fr.fr) {
			sumtot+= (extras[re].fr.sc-extras[re].fr.fr+1)*extras[re].sc;
			re++;
		}
		if(le == re) {
			ans = max(ans, (min(r,extras[re].fr.sc)-extras[re].fr.fr+1)*extras[re].sc);
		}
		else {
			ans = max(ans, sumtot+(min(r,extras[re].fr.sc)-extras[re].fr.fr+1)*extras[re].sc);
			sumtot-= (extras[le].fr.sc-extras[le].fr.fr+1)*extras[le].sc;
		}
	}

	int final = 1e9+1;
	for(int i = 0; i < extras.size(); i++) {
		int l = extras[i].fr.sc;
		extras[i].fr = mp(final-extras[i].fr.sc,final-extras[i].fr.fr);
	}
	reverse(all(extras));
	re = 0;
	for(int le = 0; le < extras.size(); le++) {
		// cout << final-extras[le].fr.fr << " " << final-extras[le].fr.sc << " " << extras[le].sc << endl;
		// cout << " " << extras[le].fr.fr << " " << " " << extras[le].fr.sc << " " << extras[le].sc << endl;

		int l = extras[le].fr.fr;
		int r = l+x-1;
		while(re+1 < extras.size() && r >= extras[re+1].fr.fr) {
			sumtot+= (extras[re].fr.sc-extras[re].fr.fr+1)*extras[re].sc;
			re++;
		}
		if(le == re) {
			ans = max(ans, (min(r,extras[re].fr.sc)-extras[re].fr.fr+1)*extras[re].sc);
		}
		else {
			ans = max(ans, sumtot+(min(r,extras[re].fr.sc)-extras[re].fr.fr+1)*extras[re].sc);
			sumtot-= (extras[le].fr.sc-extras[le].fr.fr+1)*extras[le].sc;
		}
	}
	cout << ans << endl;


}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int le = 0; le < extras.size(); le++) {
      |                  ~~~^~~~~~~~~~~~~~~
autobahn.cpp:59:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   while(re+1 < extras.size() && r >= extras[re+1].fr.fr) {
      |         ~~~~~^~~~~~~~~~~~~~~
autobahn.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i = 0; i < extras.size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
autobahn.cpp:74:7: warning: unused variable 'l' [-Wunused-variable]
   74 |   int l = extras[i].fr.sc;
      |       ^
autobahn.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for(int le = 0; le < extras.size(); le++) {
      |                  ~~~^~~~~~~~~~~~~~~
autobahn.cpp:85:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   while(re+1 < extras.size() && r >= extras[re+1].fr.fr) {
      |         ~~~~~^~~~~~~~~~~~~~~
autobahn.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen("in.in","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~
autobahn.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen("out.out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 474 ms 431684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 474 ms 431684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 474 ms 431684 KB Output isn't correct
2 Halted 0 ms 0 KB -