forked from hughbzhang/Competitive_Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buylow.cpp
57 lines (52 loc) · 1.38 KB
/
buylow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
ID: bigfish2
LANG: C++
TASK: buylow
*/
#include <cstdio>
#include <set>
using namespace std;
int day[6000];//prices
int num;
int best = 0;//best overall
long long cnt[6000];//number of subsequences i get from taking this
int pre[6000];//how long it is from here
set<int> vis;//whether ive taken this price b4 in counting unique subsequences
int main(){
freopen("buylow.in","r",stdin);
// freopen("buylow.out","w",stdout);
scanf("%d",&num);
for(int x = 0;x<num;x++) scanf("%d",day+x);
for(int y = num-1;y>=0;y--){
pre[y] = 1;
cnt[y] = 1;
vis.clear();
for(int x = y+1;x<num;x++){
if(day[y]>day[x]){//if this is lower
if(pre[x]>=pre[y]){//reset our best
pre[y] = pre[x]+1;
vis.clear();
cnt[y] = 0;
}
if(pre[x] == pre[y]-1&&vis.count(day[x])==0){//we'll take it
vis.insert(day[x]);
cnt[y]+=cnt[x];
}
}
}
if(pre[y]>best) best = pre[y];
}
long long ans = 0;
vis.clear();
for(int x = 0;x<num;x++){
if(pre[x] == best&&vis.count(day[x])==0){
vis.insert(day[x]);
ans+=cnt[x];
}
}
for(int x = 0;x<num;x++){
printf("%lld\n",cnt[x]);
}
printf("%d %lld\n",best,ans);
return 0;
}