F - Financial Planning

这篇博客讨论了一个关于个人退休规划的问题,涉及到股票投资和最短回本时间的计算。题目描述了一种情况,你需要通过购买股票并在股票市场中赚取利润来偿还一位亿万富翁朋友的借款并达到舒适的退休资金。每只股票有不同的每日收益和初始投资成本。通过排序股票并进行枚举计算,可以找到达到退休目标所需的最短时间。博客中提供了AC代码示例,展示了如何通过排序和枚举找到最短回本天数。

F - Financial Planning

 Kattis - financialplanning 

Being a responsible young adult, you have decided to start planning for retirement. Doing some back-of-the-envelope calculations, you figured out you need at least MM euros to retire comfortably.

You are currently broke, but fortunately a generous gazillionaire friend has offered to lend you an arbitrary amount of money (as much as you need), without interest, to invest in the stock market. After making some profit you will then return the original sum to your friend, leaving you with the remainder.

Available to you are nn investment opportunities, the ii-th of which costs c_ ici​ euros. You also used your computer science skills to predict that the ii-th investment will earn you p_ ipi​ euros per day. What is the minimum number of days you need before you can pay back your friend and retire? You can only invest once in each investment opportunity, but you can invest in as many different investment opportunities as you like.

For example, consider the first sample. If you buy only the second investment (which costs 1515 euros) you will earn p_2 = 10p2​=10 euros per day. After two days you will have earned 2020 euros, exactly enough to pay off your friend (from whom you borrowed 1515 euros) and retire with the remaining profit (55 euros). There is no way to make a net amount of 55 euros in a single day, so two days is the fastest possible.

Input

  • The first line contains the number of investment options 1 \leq n \leq 10^51≤n≤105 and the minimum amount of money you need to retire 1 \leq M \leq 10^91≤M≤109.

  • Then, nn lines follow. Each line ii has two integers: the daily profit of this investment {1 \leq p_ i \leq 10^9}1≤pi​≤109 and its initial cost 1 \leq c_ i \leq 10^91≤ci​≤109.

Output

Print the minimum number of days needed to recoup your investments and retire with at least MM euros, if you follow an optimal investment strategy.

Sample 1

InputcopyOutputcopy
2 5
4 10
10 15
2

Sample 2

InputcopyOutputcopy
4 10
1 8
3 12
4 17
10 100
6

Sample 3

InputcopyOutputcopy
3 5
4 1
9 10
6 3
1

 这个题比赛的时候队友和我都理解错题意了,浪费了不少时间,然后补题的时候想了想,每个股票都有一个最短的回血时间,我们需要的就是回血时间最短的股票,排序后枚举去取最小值;

ac代码:

#include <bits/stdc++.h>
using namespace std;
//#define long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//typedef long long;
const long long int N=1e5+7;
long long int n,m;
struct node{
    long long int earn,pay;//结构体,利润和投资;
}a[N];
int cmp(node a,node b){//比较的是最短开始回本的时间;
    return a.pay*b.earn<b.pay*a.earn;//a.y/a.x<b.y/b.x的变式,防止除数不准确;
}
int main(){
    IOS;
    cin>>n>>m;
    long long int earn=0,pay=0;
    for(int i=0;i<n;i++){
        cin>>a[i].earn>>a[i].pay;
    }
    sort(a,a+n,cmp);//
    long long int ans=1e18;
    for(int i=0;i<n;i++){//枚举
        earn+=a[i].earn;
        pay+=a[i].pay;
        if((pay+m)%earn==0){
            ans=min(ans,(m+pay)/earn);
        }
        else ans=min(ans,(m+pay)/earn+1);
    }
    cout<<ans<<endl;
    return 0;
}

这是我的答案:Business Scenario & Database Justification As the online movie platform rapidly expands, users are no longer satisfied with simply browsing popular releases—they seek personalized suggestions, reliable ratings, and detailed reviews to guide their next viewing choices. However, the existing system is incoherent, difficult to maintain, and lacks support for scalable data analysis or personalized features. To address these challenges, a relational database system has been proposed. This system aims to store, relate, and retrieve structured data efficiently across several key entities: users, movies, genres, reviews, favorites, and recommendations. A file-based or spreadsheet solution fails to offer referential integrity, concurrent access, and query efficiency, which are essential for real-time movie recommendation and review retrieval. ✅ Database Components Covered: Users, Movies, Movie_Genres, Reviews, Favorites, Recommendations Mapping tables & foreign key constraints ensure relational consistency Real-time queries enable custom experiences for each user 2. Business Rules and Assumptions The database design is grounded in the following operational rules and assumptions: 🟢 A user must register before posting reviews or receiving recommendations. 🟢 A movie can belong to multiple genres, and each genre can apply to many movies. 🟢 A review is always linked to one user and one movie only. 🟢 A user can save a movie as favorite, and each favorite entry tracks timestamp. 🟢 Movie recommendations are generated per user by algorithms, stored along with confidence scores. 🟢 Only registered users can interact with the platform. Admin-level privileges are assumed for content moderation and system management. 3. Challenges and Possible Solutions This system must address data privacy, ethical considerations, and performance bottlenecks: Privacy Concern: Storing emails and user behavior requires GDPR-compliant encryption and anonymization. → Solution: Store hashed passwords, limit access via role-based permission. Scalability Issue: As user base grows, inefficient queries may overload the system. → Solution: Normalize the data structure to 3NF, use indexes on foreign keys. Ethical Concern: Biased or abusive reviews must be handled. → Solution: Add moderation workflow and time-based filters to detect anomalies. 4. Functional Requirements The database must support the following operations to meet both user-facing and internal business needs: User Registration & Login Movie Management: Add/update/delete movie entries Genre Categorization: Link movies to multiple genres Search & Filter Movies by genre, rating, language, etc. Review Management: Users can add/edit/delete reviews Favorites Tracking: Users can save favorite movies Recommendation Delivery: Users receive algorithm-based suggestions Admin Reporting: Average ratings, top genres, user activity logs 5. Reflection on Requirement Gathering The requirements were derived by analyzing the business scenario provided, identifying gaps in user experience, and aligning database features with expected platform behavior. The use of MoSCoW prioritization and entity-relationship planning helped to balance feature inclusion against system complexity. 这是我的问题: Q1: Requirements Description (Marks 20) You will begin the project by working on the above given topic. You will identify your companies business requirements by doing some search / research. Identify the business requirements that will allow you to understand the business processes. Build a list of business needs, rules and assumptions based on your scenario. Use the following categories to help you with this:  Business Scenario: A business scenario describes a specific situation or context in which a business operates, including its processes, requirements, goals, and challenges. It outlines the need for a solution (e.g., a database) and defines how the solution will address the needs of the business. In the context of database design, the scenario should clarify why the database is necessary, what it aims to achieve, and how it fits into the business workflow.You should clearly state the need for a database and identify its components in paragraphs. Why its important to design a database instead of spreadsheet or file system in the context of problem mentioned? Usually, one paragraph pertains to one or more tables and relationships.  Business rules and assumptions: Business rules and assumptions are foundational elements in database design that help define how a business operates and how its data is structured, managed, and processed. These elements ensure that the database accurately reflects the real-world processes and constraints of the organization. It is used to understand business processes and the nature, role, and scope of the data. For Example, I) A customer cannot place an order without registering in the system; ii) Each product have a unique product ID etc.  Problems and possible solutions: In the context of database design, problems and possible solutions refer to the challenges that arise due to various legal, ethical, financial, or operational considerations that need to be addressed to ensure the database functions effectively within the given business environment. Identifying these challenges early allows the designer to propose practical solutions that minimize risks and optimize performance. These problems can be defined as legal, ethical, and financial considerations that requires attention and a possible solution to alleviate the situation. Functional Requirements: Functional requirements specify the actions and features a system must perform to meet user needs. For the movie database, the focus will be on features or functionalities like movie management (add, update, delete), search and filter options, to name a few for a seamless user experience. Write the list of functionalities for the database system you design or gather the requirements. 请基于我的答案 对我的问题生成一个思维导图解决问题
05-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值