結果

問題 No.489 株に挑戦
ユーザー vjudge1
提出日時 2025-01-30 21:44:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 1,000 ms
コード長 628 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 193,104 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-30 21:45:02
合計ジャッジ時間 4,054 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%lld%lld%lld",&n,&D,&K);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:13:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         FL(i,1,n) scanf("%lld",&a[i]);
      |                   ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define FL(i,a,b) for(ll i=(a);i<=(b);i++)
#define FR(i,a,b) for(ll i=(a);i>=(b);i--)
#define ll long long
#define PII pair<ll,ll>
using namespace std;
const ll MAXN = 1e5 + 10;
ll a[MAXN],q[MAXN];
PII pos;
signed main(){
	ll n,D,K,ans=0;
	scanf("%lld%lld%lld",&n,&D,&K);
	FL(i,1,n) scanf("%lld",&a[i]);
	ll l=1,r=0;
	FL(i,1,n){
		while(l<=r&&i-q[l]>D) l++;
		while(l<=r&&a[q[r]]>a[i]) r--;
		if(l<=r){
			ll res=(a[i]-a[q[l]])*K;
			if(res>ans){
				ans=res;
				pos={q[l],i};
			}
		}
		q[++r]=i;
	}
	if(!ans) puts("0"),exit(0);
	printf("%lld\n",ans);
	printf("%lld %lld\n",pos.first-1,pos.second-1);
}
0