#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int absSum(vector<int> &k){
int sum = 0;
for(auto &i: k) sum += abs(i);
return sum;
}
void solve(){
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int> (m));
for(vector<int> &i: a)
for(int &j: i)
cin >> j;
pair<int, int> ans = {absSum(a[0]), 0};
for(int i = 1; i < n; i++){
int curSum = absSum(a[i]);
if(curSum > ans.first) ans = {curSum, i};
cout << "Line #" << (ans.second + 1) << " has the biggest absolute sum: " << ans.first;
signed main() {
solve();
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int absSum(vector<int> &k){
int sum = 0;
for(auto &i: k) sum += abs(i);
return sum;
}
void solve(){
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int> (m));
for(vector<int> &i: a)
for(int &j: i)
cin >> j;
pair<int, int> ans = {absSum(a[0]), 0};
for(int i = 1; i < n; i++){
int curSum = absSum(a[i]);
if(curSum > ans.first) ans = {curSum, i};
}
cout << "Line #" << (ans.second + 1) << " has the biggest absolute sum: " << ans.first;
}
signed main() {
solve();
}