D. R2D2 and Droid Army(two pointers)
来源:互联网 发布:shp矢量数据下载 编辑:程序博客网 时间:2024/05/16 15:53
An army of n droids is lined up in one row. Each droid is described bym integers a1, a2, ..., am, whereai is the number of details of thei-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He hasm weapons, the i-th weapon can affect all the droids in the army by destroying one detail of thei-th type (if the droid doesn't have details of this type, nothing happens to it).
A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at mostk shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?
The first line contains three integers n, m, k (1 ≤ n ≤ 105,1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively.
Next n lines follow describing the droids. Each line containsm integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of details of thei-th type for the respective robot.
Print m space-separated integers, where thei-th number is the number of shots from the weapon of thei-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.
If there are multiple optimal solutions, print any of them.
It is not necessary to make exactly k shots, the number of shots can be less.
5 2 44 01 22 10 21 3
2 2
3 2 41 21 32 2
1 3
In the first test the second, third and fourth droids will be destroyed.
In the second test the first and second droids will be destroyed.
AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <set>#include <map>#include <queue>#include <vector>#include <cstdlib>#include <algorithm>#define ls u << 1#define rs u << 1 | 1#define lson l, mid, u << 1#define rson mid + 1, r, u << 1 | 1#define INF 0x3f3f3f3f#define MAX 4using namespace std;typedef long long ll;const int M = 1e5 + 100;const int mod = 2147483647;multiset<int>mp[10];int a[M][10],res[10];int main(){ int n,m,k,len = 0; cin>>n>>m>>k; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) scanf("%d",&a[i][j]); for(int l = 0,r = 0; r < n; r++){ for(int i = 0; i < m; i++){ mp[i].insert(a[r][i]); } while(l <= r){ int sum = 0; for(int i = 0; i < m; i++) sum += *mp[i].rbegin(); if(sum <= k) break; for(int i = 0; i < m; i++) mp[i].erase(mp[i].find(a[l][i])); l++; } if(len < r - l + 1){ len = r - l + 1; for(int i = 0; i < m; i++) res[i] = *mp[i].rbegin(); } } for(int i = 0; i < m; i++){ if(i) putchar(' '); printf("%d",res[i]); } return 0;}
- D. R2D2 and Droid Army(two pointers)
- codeforces 514D R2D2 and Droid Army
- CodeForces 514D R2D2 and Droid Army
- CodeForces 514D-R2D2 and Droid Army
- R2D2 and Droid Army : CodeForces
- R2D2 and Droid Army - CodeForces 514 D 二分
- Codeforces Round #291 (Div. 2)---D. R2D2 and Droid Army
- cf291 div2 D. R2D2 and Droid Army 二分+RMQ
- Codeforces Round #291 (Div. 2)D. R2D2 and Droid Army
- codeforces 514d R2D2 and Droid Army (RMQ+二分)
- Codeforces 514D R2D2 and Droid Army RMQ问题
- CodeForces 514D R2D2 and Droid Army RMQ+二分
- Codeforces Round #291 (Div. 2) D - R2D2 and Droid Army
- Codeforces 514 D R2D2 and Droid Army(RMQ+二分)
- 【CF 514D】 R2D2 and Droid Army (线段树、RMQ)
- CodeForces 518D - R2D2 and Droid Army(概率dp)
- Codeforces 514D R2D2 and Droid Army【二分+RMQ】
- Codeforces 514D R2D2 and Droid Army RMQ问题
- TCP/IP协议学习
- 1046
- Problem 045——UVa 512 - Spreadsheet Tracking
- (动态规划)能量项链
- 触发器
- D. R2D2 and Droid Army(two pointers)
- 明明的随机数
- hdu 1007 Quoit Design
- 开心的金明
- 收集宝藏
- C语言学习笔记之位运算求余
- 服务器架设笔记——打通MySQL和Apache
- hdu1281---棋盘游戏
- poj--3630+字典树基础题