답안 #15736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15736 2015-07-19T05:09:36 Z cki86201 정전 (OJUZ10_blackout) C++
컴파일 오류
0 ms 0 KB
#include<stdio.h>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> Pi;
#define X first
#define Y second

Pi q[300030];
int p[150020];
int cnt[2];
ll ans;

int main(){
	int n, l;
	scanf("%d%d",&n,&l);
	for(int i=0;i<n;i++)scanf("%d",p+i);
	sort(p, p+n);
	for(int i=0;i<n;i++){
		q[i+i] = Pi(p[i]-l, i);
		q[i+i+1] = Pi(p[i]+l, n+i);
	}
	sort(q, q+n+n);
	for(int i=0;i<n+n;i++){
		if(i > 0 && cnt[0] > 0 && cnt[1] > 0)ans += (ll)q[i].X - q[i-1].X;
		if(q[i].Y < n)cnt[q[i].Y&1]++;
		else cnt[(q[i].Y-n)&1]--;
	}
	printf("%lld",ans);
	return 0;
}

Compilation message

blackout.cpp: In function ‘int main()’:
blackout.cpp:19:13: error: ‘sort’ was not declared in this scope
  sort(p, p+n);
             ^
blackout.cpp:17:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&l);
                     ^
blackout.cpp:18:37: 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",p+i);
                                     ^