Submission #276634

# Submission time Handle Problem Language Result Execution time Memory
276634 2020-08-20T14:35:19 Z arnold518 Radio (Balkan15_RADIO) C++14
0 / 100
2000 ms 256 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000;

struct Data
{
	int X, P, S;
};

int N, K;
Data A[MAXN+10];

int main()
{
	scanf("%d%d", &N, &K);
	for(int i=1; i<=N; i++) scanf("%d%d%d", &A[i].X, &A[i].P, &A[i].S);
	if(N==1) return !printf("0\n");

	ll ans=1e18;
	for(int i=1; i<N; i++)
	{
		ll lo=A[i].X, hi=A[i+1].X;
		/*
		while(lo+2<hi)
		{
			ll mid1=(lo*2+hi)/3, mid2=(lo+hi*2)/3;
			ll val1=0, val2=0;

			for(int j=1; j<=i; j++) val1+=max(0ll, mid1-A[j].X-A[j].P);
			for(int j=i+1; j<=N; j++) val1+=max(0ll, A[j].X-A[j].P-mid1);

			for(int j=1; j<=i; j++) val2+=max(0ll, mid2-A[j].X-A[j].P);
			for(int j=i+1; j<=N; j++) val2+=max(0ll, A[j].X-A[j].P-mid2);

			if(val1<=val2) hi=mid2;
			else lo=mid1;
		}
		*/

		for(ll k=lo; k<=hi; k++)
		{
			ll val=0;
			for(int j=1; j<=i; j++) val+=max(0ll, k-A[j].X-A[j].P);
			for(int j=i+1; j<=N; j++) val+=max(0ll, A[j].X-A[j].P-k);
			ans=min(ans, val);
		}
	}
	printf("%lld\n", -ans);
}

Compilation message

radio.cpp: In function 'int main()':
radio.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
radio.cpp:21:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  for(int i=1; i<=N; i++) scanf("%d%d%d", &A[i].X, &A[i].P, &A[i].S);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2099 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2099 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -