CodeForces - I Don't Want To Pay For The Late Jar!

522 篇文章 3 订阅
99 篇文章 0 订阅

题目链接:http://codeforces.com/gym/102219/problem/C
Time limit per test 1.0 s Memory limit per test 256 MB

Description

Nina from the IT support needs your help with another daily puzzle she faces. She is able to take her lunch break anytime she wants. But because of limited capacity, she only can take S minutes based on the needs that day. Any extra minutes that she is late, she has to pay RM1 to the late jar.

She prepared a list of her favorite restaurants and how long it would take for her to lunch in each restaurant based on experience, (1 ≤ ti ≤ 109 ). She also assigned a value for each of the restaurants that shows how much extra she is willing to pay but still be happy, (1 ≤ fi ≤ 10^9 ).

For example, if she needs tx minutes to dine in restaurant x which she values RMfx . If tx≤S then she is fully happy and it is as if she saved RMfx.

But if tx>S she would save fx−(tx−S).

Please help her to find the restaurant that she would be happiest in and meanwhile save the most. Also, keep in mind she can choose exactly one restaurant to lunch each day.

Input

The first line contains an integer – D(1≤D≤10) – the number of days.

The second line contains two space-separated integers — N(1≤N≤104) and S(1≤S≤109) — the number of restaurants in Nina's list and her lunch break time for the day, correspondingly.

Each of the next N lines contains two space-separated integers — fi(1≤fi≤109) and ti (1≤ti≤109) — the characteristics of the ith restaurant.

Output

In a single line print a single integer — the maximum money she is saving/her happiness by day.

Example

input

2
2 5
3 3
4 5

1 5
1 7

output

Case #1: 4
Case #2: -1

Problem solving report:

Description: 给你一个总时间S和每个餐厅吃午餐的时间ti和愿意支付的额外费用fi,如果ti<=S,那么他会得到fi的幸福值,否则他会得到fi-(ti-S)的幸福值,求他在一个餐厅吃饭能得到的最大幸福值。
Problem solving: 直接判断求最大值就行了,注意有负数,初始值不能附为0。

Accepted Code:

/* 
 * @Author: lzyws739307453 
 * @Language: C++ 
 */
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
    int t, n, m, kase = 0;
    scanf("%d", &t);
    while (t--) {
        int max_ = -inf;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; i++) {
            int u, v;
            scanf("%d%d", &u, &v);
            if (v <= m)
                max_ = max(max_, u);
            else max_ = max(max_, u - (v - m));
        }
        printf("Case #%d: %d\n", ++kase, max_);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
CodeForces - 616D是一个关于找到一个序列中最长的第k好子段的起始位置和结束位置的问题。给定一个长度为n的序列和一个整数k,需要找到一个子段,该子段中不超过k个不同的数字。题目要求输出这个序列最长的第k好子段的起始位置和终止位置。 解决这个问题的方法有两种。第一种方法是使用尺取算法,通过维护一个滑动窗口来记录\[l,r\]中不同数的个数。每次如果这个数小于k,就将r向右移动一位;如果已经大于k,则将l向右移动一位,直到个数不大于k。每次更新完r之后,判断r-l+1是否比已有答案更优来更新答案。这种方法的时间复杂度为O(n)。 第二种方法是使用枚举r和双指针的方法。通过维护一个最小的l,满足\[l,r\]最多只有k种数。使用一个map来判断数的种类。遍历序列,如果当前数字在map中不存在,则将种类数sum加一;如果sum大于k,则将l向右移动一位,直到sum不大于k。每次更新完r之后,判断i-l+1是否大于等于y-x+1来更新答案。这种方法的时间复杂度为O(n)。 以上是两种解决CodeForces - 616D问题的方法。具体的代码实现可以参考引用\[1\]和引用\[2\]中的代码。 #### 引用[.reference_title] - *1* [CodeForces 616 D. Longest k-Good Segment(尺取)](https://blog.csdn.net/V5ZSQ/article/details/50750827)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces616 D. Longest k-Good Segment(双指针+map)](https://blog.csdn.net/weixin_44178736/article/details/114328999)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ityanger

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值