2019The 44th International Collegiate Programming Contest Asia Shenyang Regional Contest

2019ICPC沈阳重现赛

镇楼
比赛链接

Problem A. Leftbest

Description

Jack is worried about being single for his whole life, so he begins to use a famous dating app. In this
app, the user is shown single men/women’s photos one by one, and the user may choose between “yes”
and “no”. Choosing “yes” means an invitation while choosing “no” means nothing. The photos would be
shown one by one until the number of rest photos to be shown reaches zero. Of course, efficient and single Jack would always choose “yes”.
When viewing photos, Jack would have a “fake impression point” on every photo, which is not accurate.
To calculate the “true impression point” of one photo, Jack would recall the “fake impression point” of
every previous photo whose “fake impression point” is larger than this photo, and regard the smallest
“fake impression point” of them as the “true impression point” of this photo. Jack would like to sum the
“true impression point” of all photos as the outcome of his effffort.
Note that if such a larger “fake impression point” does not exist, the “true impression point” of this photo
is zero.

Input

The fifirst line contains an integer n (1 ≤ n ≤ 100 000) — the number of photos.
The second line contains n integers a1, a2, . . ., an where ai (0 ≤ ai ≤ 10^8) is the “fake impression point”
of the i-th photo.

Output

Output a single integer — the sum of the “true impression point” of all photos.

样例

题意

给出一个列数,每个数找出其前面的数中比他大的数中最小的一个,求这些值的和。
PS:暴力肯定会超时,所以用了复杂度最低的排序sort,然后再用upper_bound寻找,代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#inclu
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值