【无标题】New Year‘s Problem

本文介绍了一种贪心算法思路,用于在给定条件下为朋友选择礼物,通过寻找每个商店次大价值并组合,最后找到满足条件的最小礼物价值。博客详细阐述了问题背景、解决方案和代码实现,适合Codeforces Problem-D挑战。
摘要由CSDN通过智能技术生成

思路:贪心,先寻找每个商店中次大值最大的商店,然后选择给每个朋友礼物的最大值,在这n+1个数中选择最小的,就是答案

代码:

#include<iostream>
#include <cstring>
#include <vector>
using namespace std;
const int N=1e5+10,mol=2e9+20;

int x[N];
bool st[N];
int n,m;
void sove()
{
    
    cin>>m>>n;vector<int>v[m+1];
    int ans=0;
    for(int i=1;i<=m;i++)
    {
        int ma=0,cma=0;
        for(int j=0;j<n;j++)
        {
            long long a;
            cin>>a;
            v[i].push_back(a);
            if(a>ma)cma=ma,ma=a;
            else if(a>cma)cma=a;
        }
        ans=max(cma,ans);
    }
    for(int i=0;i<n;i++)
    {
        int rec=0;
        for(int j=1;j<=m;j++)
        rec=max(rec,v[j][i]);
        ans=min(rec,ans);
    }
    cout<<ans<<endl;
}
int main  ()
{std::ios::sync_with_stdio(false);cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)sove();
}

Problem - D - Codeforces

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值