Submission #242325

#TimeUsernameProblemLanguageResultExecution timeMemory
242325shenxy3단 점프 (JOI19_jumps)C++11
32 / 100
4067 ms7016 KiB
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
int main() {
	int N, Q, L, R;
	scanf("%d", &N);
	int A[N];
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	scanf("%d", &Q);
	if (Q == 1) {
		scanf("%d %d", &L, &R);
		--L, --R;
		vector<int> st;
		vector<ii> gps;
		for (int i = L; i <= R; ++i) {
			while (!st.empty() && A[st.back()] <= A[i]) gps.push_back(ii(st.back(), i)), st.pop_back();
			if (!st.empty()) gps.push_back(ii(st.back(), i));
			st.push_back(i);
		}
		int ans = 0, SA[R - L + 1];
		SA[R - L] = A[R];
		for (int i = R - 1; i >= L; --i) SA[i - L] = max(SA[i - L + 1], A[i]);
		for (ii i: gps) {
			if (2 * i.second - i.first - L <= R) ans = max(ans, A[i.first] + A[i.second] + SA[2 * i.second - i.first - L]);
		}
		printf("%d", ans);
		return 0;
	}
	for (int i = 0; i < Q; ++i) {
		scanf("%d %d", &L, &R);
		--L, --R;
		int ans = 0;
		for (int i = L; i <= R; ++i) {
			for (int j = i + 1; j <= R; ++j) {
				for (int k = j + j - i; k <= R; ++k) ans = max(ans, A[i] + A[j] + A[k]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
jumps.cpp:10:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
                              ~~~~~^~~~~~~~~~~~~
jumps.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
jumps.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &L, &R);
   ~~~~~^~~~~~~~~~~~~~~~~
jumps.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &L, &R);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...