B. Bets

B. Bets
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.

To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:

    • li — the number of the starting section,

    • ri — the number of the finishing section (li ≤ ri),

    • ti — the time a biathlete needs to complete an section of the path,

    • ci — the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.

      The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives k·ciroubles.

      In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.

      We should also add that Nikita can bet on each section and on any contestant running in this section.

      Help the friends find the maximum possible profit.

    Input

    The first line contains two integers n and m (1 ≤ n, m ≤ 100). Then follow m lines, each containing 4 integers liritici (1 ≤ li ≤ ri ≤ n1 ≤ ti, ci ≤ 1000).

    Output

    Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.

    Sample test(s)
    input
    4 4
    1 4 20 5
    1 3 21 10
    3 3 4 30
    3 4 4 20
    
    output
    60
    input
    8 4
    1 5 24 10
    2 4 6 15
    4 6 30 50
    6 7 4 20
    
    output
    105
    Note

    In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.

    In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.

    http://codeforces.com/problemset/problem/69/B

    #include <iostream>
    #include <string.h>
    using namespace std;
    struct node
    {
        int ti,d;
    }t[111];
    void add(int a,int b,int c,int d)
    {
        int i;
        for(i=a;i<=b;i++)
        {
            if(t[i].ti>c||!t[i].ti)
            {
                t[i].ti=c;
                t[i].d=d;
            }
        }
    }
    int main()
    {
        int n,m,i,a,b,c,d;
        while(cin>>n>>m)
        {
            memset(t,0,sizeof(t));
            for(i=0;i<m;i++)
            {
                cin>>a>>b>>c>>d;
                add(a,b,c,d);
            }
           int s=0;
            for(i=1;i<=n;i++)
            {
               s+=t[i].d;
            }
            cout<<s<<endl;
    
        }
        return 0;
    }


    • 0
      点赞
    • 1
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    以下是一个示例爬虫代码,使用 Python 编写,需要安装 requests 和 BeautifulSoup 库: ```python import requests from bs4 import BeautifulSoup import random import time # 构造请求头和参数 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36' } params = { 'pn': '1', 'fltt': '2', 'invt': '2', 'fid': 'f3', 'fs': 'm:0+t:6,m:0+t:13,m:0+t:80,m:1+t:2,m:1+t:23', 'fields': 'f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f23,f24,f25,f26,f27,f28' } # 随机生成后两位学号 suffix = str(random.randint(0, 99)).zfill(2) print('我的学号后两位为:{}'.format(suffix)) # 构造请求URL url = 'http://quote.eastmoney.com/stocklist.html#sz' + suffix # 发送请求并解析HTML response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') # 获取股票代码和名称列表 stock_list = [] links = soup.select('div.quotebody > div.quotecontent > ul > li > a') for link in links: href = link['href'] if href.startswith('/sh') or href.startswith('/sz'): stock_code = href[3:9] stock_name = link.text stock_list.append((stock_code, stock_name)) # 随机选择一只股票并获取详细信息 if stock_list: stock_code, stock_name = random.choice(stock_list) print('爬取时间:{}'.format(time.strftime('%Y年%m月%d日 %H:%M:%S'))) print('相应股票信息为:{} {}'.format(stock_code, stock_name)) detail_url = 'https://gupiao.baidu.com/stock/{}.html'.format(stock_code) response = requests.get(detail_url, headers=headers, params=params) soup = BeautifulSoup(response.text, 'html.parser') div = soup.select_one('div.stock-bets') if div: name = div.select_one('a.stock-bets-name').text.strip() price = div.select_one('strong.stock-bets-price').text.strip() change = div.select_one('span.stock-bets-change').text.strip() print('股票名称:{}'.format(name)) print('当前价格:{}'.format(price)) print('涨跌幅:{}'.format(change)) else: print('没有找到相应的股票详细信息!') else: print('没有找到相应的股票!') ``` 注意:该代码仅供学习参考,不应用于商业用途。在实际使用时,应该遵守相关法律法规和网站的使用协议。

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值