首页 > 代码库 > hdu 4296 贪心
hdu 4296 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=4296
找sum-w[i]-s[i]的最小值就行了,O(n)
//#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #include <map> #include <set> #include <queue> using namespace std; #define ls(rt) rt*2 #define rs(rt) rt*2+1 #define ll long long #define ull unsigned long long #define rep(i,s,e) for(int i=s;i<e;i++) #define repe(i,s,e) for(int i=s;i<=e;i++) #define CL(a,b) memset(a,b,sizeof(a)) #define IN(s) freopen(s,"r",stdin) #define OUT(s) freopen(s,"w",stdout) const ll ll_INF = ((ull)(-1))>>1; const double EPS = 1e-8; const double pi = acos(-1.0); const int INF = 100000000; const int MAXN = 100000+20; int w[MAXN],s[MAXN]; int main() { int n,pos; ll sum,mmin; while(~scanf("%d",&n)) { sum=0; for(int i=0;i<n;i++) scanf("%d%d",&w[i],&s[i]),sum+=w[i]; mmin=sum-w[0]-s[0]; pos=0; for(int i=1;i<n;i++) if(mmin>sum-w[i]-s[i])pos=i,mmin=sum-w[i]-s[i]; printf("%I64d\n",mmin); } return 0; }
hdu 4296 贪心
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。