最優接單(變相的比較大小問題)

2021-10-08 17:28:02 字數 644 閱讀 4812

最優接單

描述給出乙個數字n,代表單的數量,接下來n個數,代表每單產生的收益m(-1000<=m<=1000)。請給出最優接單方法(每單耗時相同),使得在任一時刻收益最大收益最大且最後接單數量最多。

輸入單組輸入,輸入乙個n表示單的數量,接下來n行,表示每單產生的收益。

輸出給出最優的接單方法。中間用空格分開

輸入樣例 1

5-32210

24輸出樣例 1

21 4 2 0

提示n<1000000

#include

using

namespace std;

int a[

1000000];

//陣列太大時要放在main函式的外面

bool

cmp(

int x,

int y)

intmain()

sort

(a,a+n,cmp)

;for

(i=0

;i)return0;

}

在main函式裡面的陣列是開在棧區(stack),在函式外面的是開在資料區的。棧區的記憶體比較小,所以當陣列非常大的時候,就會報錯。假如把陣列放在資料區就不會出現這個問題,因為資料區的記憶體很大。

mysql中datetime比較大小問題

select sum studychj as tofflinejz from afterline where checkflag 1 and studytype 1 and studybegin 2010 01 01 00 00 00 and studyend 2010 12 01 00 00 00...

mysql中datetime比較大小問題

select sum studychj as tofflinejz from afterline where checkflag 1 and studytype 1 and studybegin 2010 01 01 00 00 00 and studyend 2010 12 01 00 00 00...

mysql中datetime比較大小問題 轉的

方法一 你也可以 select from t1 where unix timestamp time1 unix timestamp 2011 03 03 17 39 05 and unix timestamp time1 unix timestamp 2011 03 03 17 39 52 就是用u...