답안 #471093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471093 2021-09-07T05:39:58 Z robell Art Exhibition (JOI18_art) C++17
50 / 100
1000 ms 9068 KB
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define mod 1e9+7
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
pair<ll,ll> v[500000];
int N;
ll check(ll D){
	int l=0;
	int r=0;
	ll col = 0;
	ll maxv = -1e18;
	while (l<N){
		if (r!=N){
			if (v[r].first-v[l].first<=D){
				col+=v[r].second;
				r++;
			}else{
				maxv=max(col-(v[r-1].first-v[l].first),maxv);
				l++;
				col-=v[l].second;
			}
		}else{
			maxv=max(col-(v[r-1].first-v[l].first),maxv);
			l++;
			col-=v[l].second;
		}
	}
	return maxv;
}
int main(){
	setIO();
	cin >> N;
	for (int i=0;i<N;i++){
		cin >> v[i].first >> v[i].second;
	}
	sort(v,v+N);
	// ll maxD = v[N-1].first-v[0].first;
	// ll minD = 0;
	// while (minD!=maxD){
	// 	ll mid = (maxD+minD+1)/2;
	// 	if (check(mid)>=check(mid+1)){
	// 		minD=mid;
	// 	}else{
	// 		maxD=mid-1;
	// 	}
	// }
	// cout << check(minD) << " " << minD << "\n";
	ll maxv = -1e18;
	for (int i=0;i<N;i++){
		ll col = 0;
		for (int j=i;j<N;j++){
			col+=v[j].second;
			maxv=max(maxv,col-(v[j].first-v[i].first));
		}
	}
	cout << maxv << "\n";
}

Compilation message

art.cpp: In function 'void setIO(std::string)':
art.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:20:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 20 ms 528 KB Output is correct
28 Correct 17 ms 520 KB Output is correct
29 Correct 18 ms 460 KB Output is correct
30 Correct 21 ms 524 KB Output is correct
31 Correct 17 ms 528 KB Output is correct
32 Correct 18 ms 520 KB Output is correct
33 Correct 18 ms 460 KB Output is correct
34 Correct 18 ms 524 KB Output is correct
35 Correct 17 ms 460 KB Output is correct
36 Correct 17 ms 460 KB Output is correct
37 Correct 17 ms 524 KB Output is correct
38 Correct 23 ms 524 KB Output is correct
39 Correct 17 ms 520 KB Output is correct
40 Correct 21 ms 460 KB Output is correct
41 Correct 17 ms 460 KB Output is correct
42 Correct 18 ms 528 KB Output is correct
43 Correct 17 ms 520 KB Output is correct
44 Correct 18 ms 520 KB Output is correct
45 Correct 17 ms 520 KB Output is correct
46 Correct 19 ms 524 KB Output is correct
47 Correct 17 ms 520 KB Output is correct
48 Correct 18 ms 460 KB Output is correct
49 Correct 17 ms 524 KB Output is correct
50 Correct 17 ms 460 KB Output is correct
51 Correct 17 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 20 ms 528 KB Output is correct
28 Correct 17 ms 520 KB Output is correct
29 Correct 18 ms 460 KB Output is correct
30 Correct 21 ms 524 KB Output is correct
31 Correct 17 ms 528 KB Output is correct
32 Correct 18 ms 520 KB Output is correct
33 Correct 18 ms 460 KB Output is correct
34 Correct 18 ms 524 KB Output is correct
35 Correct 17 ms 460 KB Output is correct
36 Correct 17 ms 460 KB Output is correct
37 Correct 17 ms 524 KB Output is correct
38 Correct 23 ms 524 KB Output is correct
39 Correct 17 ms 520 KB Output is correct
40 Correct 21 ms 460 KB Output is correct
41 Correct 17 ms 460 KB Output is correct
42 Correct 18 ms 528 KB Output is correct
43 Correct 17 ms 520 KB Output is correct
44 Correct 18 ms 520 KB Output is correct
45 Correct 17 ms 520 KB Output is correct
46 Correct 19 ms 524 KB Output is correct
47 Correct 17 ms 520 KB Output is correct
48 Correct 18 ms 460 KB Output is correct
49 Correct 17 ms 524 KB Output is correct
50 Correct 17 ms 460 KB Output is correct
51 Correct 17 ms 520 KB Output is correct
52 Execution timed out 1069 ms 9068 KB Time limit exceeded
53 Halted 0 ms 0 KB -