fork(2) download
  1. //#pragma GCC optimize("O3, unroll-loops")
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define fr(n) for(ll i = 0; i < n; i++)
  8. #define rep(i,a,b) for(int i = a; i < b; i++)
  9. #define vll vector<pair<ll,ll>>
  10. #define vii vector<pair<int,int>>
  11. #define pi acos(-1)
  12. #define all(v) (v).begin(),(v).end()
  13. #define mp make_pair
  14. #define print(a) for(auto x:(a))cout << x <<
  15. #define ios ios::sync_with_stdio(0);cin.tie(0);
  16. #define endl "\n"
  17. #define INF (ll)1e15
  18. #define int ll
  19.  
  20. using namespace std;
  21.  
  22. void solve(){
  23. int n, m, k; cin >> n >> m >> k;
  24. vector<vector<int>> vec(m, vector<int>(n));
  25. rep(i,0,n){
  26. rep(j,0,m){
  27. cin >> vec[j][i];
  28. }
  29. }
  30. vector<multiset<int>> msets(m);
  31. int mx = -1;
  32. int l=0, r=-1;
  33. pair<int,vector<int>> ans;
  34. while(r < n){
  35. int cur=0;
  36. vector<int> aux;
  37. for(int i = 0;i<m;++i){
  38. int temp=msets[i].size() ? *msets[i].rbegin() : 0;
  39. cur += temp;
  40. aux.push_back(temp);
  41. }
  42. if(cur <= k){
  43. ans = max(ans,make_pair(r-l+1,aux));
  44. r++;
  45. for(int i = 0;i<m;++i) msets[i].insert(vec[i][r]);
  46. }else{
  47. for(int i = 0;i<m;++i) msets[i].erase(msets[i].find(vec[i][l]));
  48. l++;
  49. }
  50. }
  51. for(auto &x:ans.second)
  52. cout << x << " ";
  53.  
  54. }
  55.  
  56.  
  57.  
  58. int32_t main() {
  59. ios
  60. int t = 1;
  61. //cin >> t;
  62. int tt = 1;
  63. while (t--){
  64. //cout << "Case " << tt++ << ": " << endl;
  65. solve();
  66. }
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5288KB
stdin
5 2 4
4 0
1 2
2 1
0 2
1 3
stdout
2 2