提出 #2391766


ソースコード 拡げる

Copy
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100005;

int n;
LL C;
LL a[N];
int val[N];
LL pre[N];

int main(){
	n=get();
	scanf("%lld",&C);
	fo(i,1,n)scanf("%lld %d",&a[i],&val[i]);
	pre[0]=0;
	fo(i,1,n)pre[i]=pre[i-1]+val[i];
	LL ans=0;
	LL tmp;
	fo(i,1,n){
		tmp=pre[i]-a[i];
		if (tmp>ans)ans=tmp;
	}
	fo(i,1,n){
		tmp=pre[n]-pre[i-1]-(C-a[i]);
		if (tmp>ans)ans=tmp;
	}
	//pre[i]+pre[n]-pre[j-1]-(2*a[i]+C-a[j])
	LL pv=-1e16;
	fd(i,n,1){
		LL tmp=pre[i]-a[i]*2+pv;
		if (tmp>ans)ans=tmp;
		if (pre[n]-pre[i-1]-(C-a[i])>pv)pv=pre[n]-pre[i-1]-(C-a[i]);
	}
	pv=-1e16;
	fd(i,n,1){
		LL tmp=pre[i]-a[i]+pv;
		if (tmp>ans)ans=tmp;
		if (pre[n]-pre[i-1]-2ll*(C-a[i])>pv)pv=pre[n]-pre[i-1]-2ll*(C-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

提出情報

提出日時
問題 D - Static Sushi
ユーザ samjia2000
言語 C++14 (GCC 5.4.1)
得点 500
コード長 1298 Byte
結果 AC
実行時間 27 ms
メモリ 2176 KB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&C);
                  ^
./Main.cpp:42:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  fo(i,1,n)scanf("%lld %d",&a[i],&val[i]);
                                         ^

ジャッジ結果

セット名 Sample Subtask1 Subtask2
得点 / 配点 0 / 0 300 / 300 200 / 200
結果
AC × 4
AC × 29
AC × 50
セット名 テストケース
Sample a01, a02, a03, a04
Subtask1 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29
Subtask2 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50
ケース名 結果 実行時間 メモリ
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
a04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 1 ms 256 KB
b11 AC 1 ms 256 KB
b12 AC 1 ms 256 KB
b13 AC 1 ms 256 KB
b14 AC 1 ms 256 KB
b15 AC 1 ms 256 KB
b16 AC 1 ms 256 KB
b17 AC 1 ms 256 KB
b18 AC 1 ms 256 KB
b19 AC 1 ms 256 KB
b20 AC 1 ms 256 KB
b21 AC 1 ms 256 KB
b22 AC 1 ms 256 KB
b23 AC 1 ms 256 KB
b24 AC 1 ms 256 KB
b25 AC 1 ms 256 KB
b26 AC 1 ms 256 KB
b27 AC 1 ms 256 KB
b28 AC 1 ms 256 KB
b29 AC 1 ms 256 KB
c30 AC 18 ms 2176 KB
c31 AC 23 ms 2176 KB
c32 AC 27 ms 2176 KB
c33 AC 27 ms 2176 KB
c34 AC 27 ms 2176 KB
c35 AC 18 ms 2176 KB
c36 AC 27 ms 2176 KB
c37 AC 26 ms 2176 KB
c38 AC 26 ms 2176 KB
c39 AC 26 ms 2176 KB
c40 AC 26 ms 2176 KB
c41 AC 26 ms 2176 KB
c42 AC 26 ms 2176 KB
c43 AC 4 ms 512 KB
c44 AC 26 ms 2176 KB
c45 AC 1 ms 256 KB
c46 AC 26 ms 2176 KB
c47 AC 1 ms 256 KB
c48 AC 26 ms 2176 KB
c49 AC 26 ms 2176 KB
c50 AC 27 ms 2176 KB