Codeforces Round #252 (Div. 2)
はい。
http://codeforces.com/contest/441
A. Valera and Antique Items
ざっくりと大意
・nの骨董売りの在庫は\(k_i\)個。
・読みにくい。
方針のようなもの
・後で。
B. Valera and Fruits
ざっくりと大意
・Valeraはガーデニングでフルーツの苗をn本育てている。
・i番目の苗は\(b_i\)個の実をつけて、\(a_i\)か\(a_i\)+1日の間に収穫できる。
・但し、一日あたりの収穫はvまでしか行わない。
方針のようなもの
・aが同じ日があるのと、aの一番大きい日の次の日も残りがあるなら収穫可能なことに気をつける。
n,v=map(int,raw_input().split()) ans=chk=0 l=[0]*3002 for i in range(n): a,b=map(int,raw_input().split()) l[a]+=b for i in range(3002): h=0 if chk<=v: h=chk else: h=v chk=l[i] if h<v: if v>=chk+h: h+=chk chk=0 else: chk-=(v-h) h=v ans+=h print ans
#include<iostream> #include<cmath> #include<string> #include<cctype> #include<vector> #include<numeric> #include<algorithm> using namespace std; /** vector<int>ar(3); for(auto&e:ar){ scanf("%d",&e); } sort(ar.begin(),ar.end()) int sum=accumulate(ar.begin(),ar.end(),0); **/ int main(){ double pai=3.141592653589; int n,v; long long ans=0,chk=0; int bs[3002]; for(int i=0;i<3002;i++){ bs[i]=0; } scanf("%d %d",&n,&v); for(int i=0;i<n;i++){ int a,b; scanf("%d %d",&a,&b); bs[a]+=b; } for(int i=0;i<3002;i++){ int h=0; if(chk<=v){ h=chk; }else{ h=v; } chk=bs[i]; if(h<v){ if(v>=chk+h){ h+=chk; chk=0; }else{ chk-=(v-h); h=v; } } ans+=h; } printf("%I64d\n",ans); return 0; }
実がなる最終日+1日まで見忘れたりとか、翌日持ち越し分の計算とかを間違えたりとかすごく無駄にしょぼかった。。