답안 #119081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119081 2019-06-20T09:42:57 Z Bruteforceman Cambridge (info1cup18_cambridge) C++11
30 / 100
2000 ms 1984 KB
#include "bits/stdc++.h"
using namespace std;
typedef pair <int, int> pii;
int t[100010], d[100010];
int opt[100010];

int query(int x, int y) {
	vector <pii> v;
	for(int i = x; i <= y; i++) {
		v.emplace_back(d[i], t[i]);
	}
	sort(v.begin(), v.end());
	long long sum = 0;
	for(int i = 0; i < v.size(); i++) {
		sum += v[i].second;
		if(sum >= v[i].first) {
			return false;
		}
	}
	return true;
}

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d %d", &t[i], &d[i]);
	}
	int cur = n;
	for(int i = n; i >= 1; i--) {
		while(cur >= i && !query(i, cur)) {
			--cur;
		}
		opt[i] = cur;
	}
	while(m--) {
		int p, q;
		scanf("%d %d", &p, &q);
		printf("%d\n", (opt[p] >= q));
	}
	return 0;
}

Compilation message

cambridge.cpp: In function 'int query(int, int)':
cambridge.cpp:14:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) {
                 ~~^~~~~~~~~~
cambridge.cpp: In function 'int main(int, const char**)':
cambridge.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
cambridge.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t[i], &d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
cambridge.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Execution timed out 2067 ms 1984 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 28 ms 768 KB Output is correct
4 Correct 38 ms 864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Execution timed out 2067 ms 1984 KB Time limit exceeded
4 Halted 0 ms 0 KB -