제출 #168012

#제출 시각아이디문제언어결과실행 시간메모리
168012GioChkhaidze금 캐기 (IZhO14_divide)C++14
100 / 100
55 ms5288 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
ll n,x[N],g[N],d[N],M[N],ans;
main () {
	scanf("%lld",&n);
	
	for (int i=1; i<=n; i++) {
		scanf("%lld%lld%lld",&x[i],&g[i],&d[i]);
		g[i]+=g[i-1];
		d[i]+=d[i-1];
		M[i]=d[i]-x[i];
	}
	
	M[n+1]=-1e18;
	for (int i=n; i>=1; i--)
		M[i]=max(M[i],M[i+1]);
		
	for (int i=1; i<=n; i++) {
		ll c=d[i-1]-x[i],l=i,r=n,mid,res;
		
		while (l<=r) {
			mid=(l+r)/2;
			if (c<=M[mid]) { res=mid; l=mid+1; }
						else r=mid-1;
		}
		
		ans=max(ans,g[res]-g[i-1]);
	}
	
	printf("%lld\n",ans);
}

컴파일 시 표준 에러 (stderr) 메시지

divide.cpp:6:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
divide.cpp: In function 'int main()':
divide.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
divide.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld",&x[i],&g[i],&d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:29:20: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans=max(ans,g[res]-g[i-1]);
               ~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...