답안 #66829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66829 2018-08-12T11:39:56 Z ege_eksi Art Exhibition (JOI18_art) C++14
0 / 100
2 ms 252 KB
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<algorithm>

using namespace std;

bool mycomp(pair<long long int,int> x , pair<long long int,int> y)
{
	if(x.first < y.first)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	
	pair<long long int,int> *a = new pair<long long int,int>[n];
	
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%lli %d" , &a[i].first , &a[i].second);
	}
	
	sort(a , a+n , mycomp);
	
	pair<long long int , long int> *d = new pair<long long int , long int>[n];
	
	int cnt = 0;
	
	d[0] = a[0];
	
	for(int i = 1 ; i < n ; i++)
	{
		if(d[cnt].first != a[i].first)
		{
			cnt++;
			d[cnt] = a[i];
		}
		else
		{
			d[cnt].second += a[i].second;
		}
	}
	
	long long int *prefix = new long long int[cnt];
	
	prefix[0] = d[0].second;
	
	for(int i = 1 ; i <= cnt ; i++)
	{
		prefix[i] = prefix[i-1] + d[i].second;
	}
	
	long long int ans = INT_MIN;

	for(int i = 0 ; i <= cnt ; i++)
	{
		for(int j = i+1 ; j <= cnt ; j++)
		{
			long long int value;
			if(i == 0)
			{
				value = prefix[j];
			}
			else
			{
				value = prefix[j] - prefix[i-1];
			}
			
			ans = max(ans , value - (d[j].first - d[i].first));
		}
	}
	
	
	printf("%d",ans);
	
	return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:84:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d",ans);
                 ^
art.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
art.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lli %d" , &a[i].first , &a[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 252 KB Output isn't correct
2 Halted 0 ms 0 KB -