Skip to content

Instantly share code, notes, and snippets.

@gedorinku
Created December 11, 2016 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gedorinku/a2eff1006ae647b063892396b35ce9a5 to your computer and use it in GitHub Desktop.
Save gedorinku/a2eff1006ae647b063892396b35ce9a5 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define PPB pop_back
#define MK make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;
constexpr int INF = 1LL << 61;
//constexpr int MOD = 1000000007;
//constexpr int MAX_N = 55;
int n, m;
vector<int> hoge;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
if (n <= a) continue;
hoge.PB(n - a);
}
sort(ALL(hoge));
int ans = 0;
for (int i = 0; i < hoge.size() - 1; ++i) ans += hoge[i];
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment