Educational Codeforces Round 21 C. Tea Party
来源:互联网 发布:景安网络免费空间 编辑:程序博客网 时间:2024/05/29 08:16
传说门
Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that:
- Every cup will contain tea for at least half of its volume
- Every cup will contain integer number of milliliters of tea
- All the tea from the teapot will be poured into cups
- All friends will be satisfied.
Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj.
For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.
The first line contains two integer numbers n and w (1 ≤ n ≤ 100, ).
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100).
Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.
If it's impossible to pour all the tea and satisfy all conditions then output -1.
2 108 7
6 4
4 41 1 1 1
1 1 1 1
3 109 8 10
-1
In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.
题目大意:n个人 一共w的茶叶。 每个人分的茶叶至少为杯子容积的1/2。先给杯子容积都装满1/2 然后再排序,给大的杯子装满,如果还有茶叶就继续给第二大的杯子装。 一直装到最小的杯子。
#include <bits/stdc++.h>//#include <ext/pb_ds/tree_policy.hpp>//#include <ext/pb_ds/assoc_container.hpp>//using namespace __gnu_pbds;using namespace std;#define pi acos(-1)#define endl '\n'#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0);#define rand() srand(time(0));typedef long long LL;typedef pair<int, int> pii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;//const int dx[]={-1,0,1,0,-1,-1,1,1};//const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=2e5+100;const double EPS=1e-9;const int MOD=1000000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;/*lch[root] = build(L1,p-1,L2+1,L2+cnt); rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*//*lch[root] = build(L1,p-1,L2,L2+cnt-1); rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}inline int Scan(){ int res=0,ch,flag=0; if((ch=getchar())=='-')flag=1; else if(ch>='0' && ch<='9')res=ch-'0'; while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0'; return flag ? -res : res;}int n, m, a[110], b[110], ord[110];bool cmp(int x,int y){ return a[x]>a[y];}int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);cin >> n >> m;for(int i = 0; i < n; i++) {cin >> a[i];b[i] = (a[i]+1) / 2;//先给每个位置都给1/2的茶叶}m -= accumulate(b, b+n, 0);/*int sum = accumulate(vec.begin() , vec.end() , 42); 将sum设置为vec的元素之和再加上42。*/if(m < 0){cout << -1 << endl;return 0;}for(int i=0;i<n;i++) ord[i]=i;sort(ord, ord+n,cmp);//排序 左边是最大排到右边最小for(int i = 0; i < n; i++){int t = min(m, a[ord[i]]-b[ord[i]]);//如果剩下的容积装满了m还有的话b[ord[i]] += t;m -= t;//m就减少 进入下一个操作}for(int i = 0; i < n; i++)cout << b[i] << (i+1 == n? '\n': ' ');return 0;}
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21-----C. Tea Party
- Educational Codeforces Round 21 C Tea Party
- codeforces Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 808C Tea Party 【贪心算法】
- Educational Codeforces Round 21 C. Tea Party 贪心
- Codeforces Educational Codeforces Round 21 [5.30] Tea Party&Array Division&Average Sleep Time&Lucky
- Codeforces 808C Tea Party
- Codeforces 808C Tea Party
- Educational Codeforces Round 21 C
- 【codeforces 808】C.Tea Party(贪心)
- Codeforces 808C Tea Party 题解
- 【Codeforces 808 C. Tea Party】+ sort
- Codeforces 808C Tea Party【贪心】
- 【Codeforces 808C】【贪心】Tea Party题解
- Educational Codeforces Round 21
- iOS 高效添加圆角效果实战讲解
- Windows7下git配置difftool
- windows拼凑wav文件
- pop3和imap读取邮箱
- 树状数组
- Educational Codeforces Round 21 C. Tea Party
- ext4日志系统分析(二)
- Java线程基本使用
- Machine Learning第九讲[异常检测] --(一)密度估计
- IP协议及IP数据包详解
- Log Structured Merge Trees译文以及LSM调研心得
- UIView的生命周期总结
- Android编译详解之lunch命令
- 解决 chorm adobe flash过期