栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

L - The Dragon Land

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

L - The Dragon Land

SDUT 2022 Spring Individual Contest(for 21) - 6 - Virtual Judge

A hero is going to make a journey through the dragon land. The dragon land is a road, and nn dragon lairs are situated along this road. The hero will follow this road, never turning back.

Passing by the dragon lair, it is possible to fight the dragon, kill him and get a_iai​ gold. But it is not always profitable to kill all the dragons, as the weapons and armor wear out: after the first battle the hero will have to spend 1 gold on repairing them, after the second battle — 2 gold, and so on, after the kk-th battle he will have to spend kk gold.

Initially the hero has no gold. At any moment of his journey and after it the hero can't have negative amount of gold.

How much gold the hero can earn in the journey?

Input

The first line contains the integer nn (1 le n le 2000001≤n≤200000) — the number of dragon lairs.

The second line contains nn integers a_iai​ (1 le a_i le 10^91≤ai​≤109) — amounts of gold the hero can earn fighting the ii-th dragon.

Output

Output one integer — the maximal hero's profit.

Sample 1

InputcopyOutputcopy
5
8 2 4 9 1
15

Sample 2

InputcopyOutputcopy
2
1 1
0

题意: 一个英雄要去龙的土地上旅行。龙地是一条路,沿着这条路有许多龙的巢穴。英雄会沿着这条路,永不回头。
路过龙穴,有可能与龙搏斗,杀死他并获得ai金。但它并不总是有利可图,杀死所有的龙、武器和盔甲磨损。在第一次战斗英雄将不得不花1黄金修复它们,在第二次战役花2黄金,k的战斗后,他将不得不花k黄金。
一开始英雄没有金子。在他的旅程的任何时刻,在此之后,英雄不可能拥有负数量的金币。
英雄在旅途中可以获得多少金币?
 

#include
using namespace std;
int n;
int a[500005];
int flag=1;
cmp(int x,int y)
{
    return x>y;
}
int main()
{
    scanf("%d",&n);
    long long sum=0,t=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1; i<=n; i++)
    {

        if(a[i]-flag>=0)
        {
            t=t+a[i]-flag;
            flag++;
        }
        else
            break;
    }

    printf("%lld",t);
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/881274.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号